Qt 更新中继器模型时布局中断

Qt 更新中继器模型时布局中断,qt,qml,qtquick2,Qt,Qml,Qtquick2,我有一个中继器嵌套在列布局中。此中继器有一个代表-矩形,其中有一个标签。问题是当模型更新时,最后一个矩形消失(标签保持可见)。代码是这样的: Repeater { id: rep model: myModel Rectangle { id: rect width: parent.width height: lab.implicitHeight + 25 color: "yellow" bo

我有一个
中继器
嵌套在
列布局中
。此
中继器
有一个代表-
矩形
,其中有一个
标签
。问题是当模型更新时,最后一个
矩形
消失(
标签
保持可见)。代码是这样的:

Repeater {
    id: rep
    model: myModel

    Rectangle {
        id: rect
        width: parent.width
        height: lab.implicitHeight + 25

        color: "yellow"
        border {
            width: 1
            color: "green"
        }

        Label {
            id: lab
            text: label
        }
    }
}

只有在面板打开时模型更新时才会出现问题,创建面板时看起来正常。

使用附加属性可以解决问题:

Rectangle {
      id: rect
      Layout.fillWidth: true
      Layout.preferredHeight: lab.implicitHeight + 25

      color: "yellow"
      ...
}

对不起,我不能提供完整和准确的代码没有人要求你的超级机密企业数据(lol)只是一个最低限度的例子显示问题。你是那样的回答者猜对了答案。干杯