中继器模型更新时布局中断
Layout breaks when repeaters model updated
我有一个 Repeater
嵌套在 ColumnLayout
中。此 Repeater
有一个委托 - Rectangle
,其中有一个 Label
。问题是当模型更新时,最后的 Rectangle
消失了(Label
保持可见)。代码是这样的:
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"
...
}
我有一个 Repeater
嵌套在 ColumnLayout
中。此 Repeater
有一个委托 - Rectangle
,其中有一个 Label
。问题是当模型更新时,最后的 Rectangle
消失了(Label
保持可见)。代码是这样的:
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"
...
}