QML- Image在布局中大小不能适应

在实际应用Image的过程中,发现加入布局中以后Image的缩放就会有问题,即使指定了

fillMode:Image.PreserveAspectFit也会发现图片显示大小虽然得到了调整,但是实际在布局中占用的宽度并没有调整
Rectangle{
    width: 800
    height: 600
    color: "white"
    RowLayout{
        Image {
            id:first
            Layout.preferredHeight: 16
            source: "qrc:/icon_sidebar_im_check.png"
            fillMode:Image.PreserveAspectFit
            horizontalAlignment: Image.AlignLeft
        }
        Image {
            id:second
            Layout.preferredHeight: 16
            source: "qrc:/icon_sidebar_im_check.png"
            fillMode:Image.PreserveAspectFit
            horizontalAlignment: Image.AlignLeft
        }
    }
}

效果如下:

QML- Image在布局中大小不能适应_第1张图片

仔细看过QML中的例子后发现,等比的缩放调节是根据Image的width和height属性来调节的,那直接设置height:16

Rectangle{
    width: 800
    height: 600
    color: "white"
    RowLayout{
        Image {
            id:first
            Layout.preferredHeight: 16
            height:16
            source: "qrc:/icon_sidebar_im_check.png"
            fillMode:Image.PreserveAspectFit
            horizontalAlignment: Image.AlignLeft
        }
        Image {
            id:second
            Layout.preferredHeight: 16
            height:16
            source: "qrc:/icon_sidebar_im_check.png"
            fillMode:Image.PreserveAspectFit
            horizontalAlignment: Image.AlignLeft
        }
    }
}

 效果如下:

OK了。 

你可能感兴趣的:(QQuick,QML,QT)