I try to add cells to my GridLayout
by using a Repeater
. My data is stored in a model and containing two properties per element:
The model-view principle assumes that each model node displays by different delegate component object. So I advice you to listen to @BaCaRoZzo's comment and do that with Column
instead of GridLayout
. Sure, QML is very flexible and you can do something like that:
Component {
id: labelDelegate
Label { text: myList.get(_index / 2).title }
}
Component {
id: textAreaDelegate
TextArea { text: myList.get(_index / 2).value }
}
ListModel {
id: myList
ListElement {title: "title1"; value: "value1"}
ListElement {title: "title2"; value: "value2"}
ListElement {title: "title3"; value: "value3"}
}
GridLayout {
anchors.fill: parent
columns: 2
Repeater {
model: myList.count * 2
delegate: Loader {
property int _index: index
sourceComponent: {
if(index % 2)
return textAreaDelegate;
else
return labelDelegate;
}
}
}
}
but that's too weird to use it in real project.