Adjust ColumnLayout when a Repeater's delegate height changes

只谈情不闲聊 提交于 2019-12-06 06:16:34

The reason might sound strange:

The [...]Layout-family is not just there to arrange the objects, but also to resize them. You are not supposed to set or alter sizes in it.

To do its job, when you don't use the available attached properties to set the sizes, it will use the implicitWidth/Height of your Items.

If you have not set implicit dimension, uppon adding new items to the layout, their implicit dimensions will be set to be equal to their set dimsions. But this is not a binding! So if you now update the height, the implicitHeight will stay at the original size, thus the Layout won't react to the change.

If you add the Column to your delegate, things change: The Column updates its implicitHeight in accordeance to the bounding rectangle of its children. If you now resize the Rectangles height, the Column will adapt the implicitHeight and the Layout will react to the change.

Now you have the following solutions:

  1. Use the Layout attached property, to set and change the size hints.
  2. Use the delegates implicitHeight instead of the height. This might be semantically wrong though.
  3. Don't use the ColumnLayout but just a regular Column when you don't need the additional layouting capatibilities (the attached properties and resizing of the Items and so on), which seems to be the case in your problem.

Column {
    anchors.centerIn: parent
    spacing: 5

    // Header goes here

    Repeater {
        model: 3
        delegate:
            Rectangle {
                width: 150
                height: width
                color: "#44ff0000"
                MouseArea {
                    anchors.fill: parent
                    onClicked: {
                        console.log(parent.implicitHeight)
                        parent.height += 50
                    }
                }

        }
    }
    // Footer goes here

}
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!