有没有简单的方法可以在QtQuick中复制行布局?
在我的ui.qml中,我有:有没有简单的方法可以在QtQuick中复制行布局?,qt,qml,qtquick2,Qt,Qml,Qtquick2,在我的ui.qml中,我有: RowLayout { id: rowLayout2 x: 0 y: 397 width: 640 height: 50 clip: false Text { id: text4 width: 105 height: 32 text: qsTr("房间类型") font.pixelSize: 17 wrapMode
RowLayout {
id: rowLayout2
x: 0
y: 397
width: 640
height: 50
clip: false
Text {
id: text4
width: 105
height: 32
text: qsTr("房间类型")
font.pixelSize: 17
wrapMode: Text.WordWrap
}
ComboBox {
id: comboBox1
activeFocusOnPress: false
model: ListModel {
id: cbItems
ListElement { text: "标准间"; color: "Yellow" }
ListElement { text: "三人间"; color: "Green" }
ListElement { text: "大床房"; color: "Brown" }
ListElement { text: "豪华套房"; color: "Blue" }
}
}
}
我想制作一个按钮,当点击它时,它会在原来的
行布局下复制这个行布局,我该怎么做呢?将它放在中继器中
并在点击按钮时增加模型
计数
Button {
onClicked: {
repeater.model += 1;
}
}
...
Column {
Repeater {
model: 1
// Your rowLayout2 code
}
}
谢谢,它工作得很好,但是编译器说“属性别名combobox:combobox1”现在无效,那么如何访问it@arslan2012假设该行在中继器
之外,它将不起作用,因为可能有多个组合框1
s。您需要提供一个getter方法来调用Repeater::itemAt(index)
,并将别名添加到rowLayout2
。然后您可以执行:repeater.itemAt(3).combobox
。