QML中缩放图片时ScrollView的滚动条不发生变化

Scrollbars of ScrollView do not change when the picture is scaled in QML

在这段代码中,当我点击zoomIn 矩形时,图片确实放大了,但是ScrollView 的默认滚动条并没有相应改变。他们保持不变。因此我无法滚动缩放的图片。

错误请指出

Rectangle {
    id: zoomIn
    height: 50; width: 50; color: "blue"
    Text { text: qsTr("Zoom In") }
    MouseArea {
        anchors.fill: parent
        onClicked: {
            currentPicture.scale += 0.5
        }
    }
}

ScrollView {
    id: head
    anchors.top: buttons.bottom
    anchors.topMargin: 30
    height: 300; width: 300
    frameVisible: true

    Image {
        id: currentPicture
        height: head.height; width: head.width
        source: folderModel1.hh
        z:0
    }
}

scale 属性 不影响它所应用的项目的 widthheight

A scale of less than 1.0 causes the item to be rendered at a smaller size, and a scale greater than 1.0 renders the item at a larger size.

ScrollView dependswidthheightcontentItem:

The width and height of the child item will be used to define the size of the content area.

既然你要放大图像,你可能只增加 widthheight 而不是 scale.


Why is the scale property there if we can bypass it without any side effects?

他们有不同的目的。我 可以 想到的一个例子是网格中的动画。以游戏中的库存网格为例。这些项目适合网格,并且网格期望它们都具有相同的宽度和高度。如果您想制作鼠标悬停效果动画,使项目在鼠标悬停时变大,您可以使用 scale 这样就不会影响实际的宽度和高度。因此,布局可能是原因之一。