I am looking for a way to access the number of elements that are to be found in a model in QML.
For example:
Item {
id: root
Row {
id: row
height: root.height
width: root.width
spacing: 5
Repeater {
id: rep
width: root.width
height: root.height
model: [5, 3, 3, 1, 12]
delegate: myDelegate
Text {
id: myDelegate
text: "Element " + index + " of " size + ":" + modelData
}
}
}
But I can't figure out how to retrieve the size of the model.
In the documentation I can find a property called count
, but no hint how to access it.
It depends on the model you're using. In your case, the model is a plain old JavaScript array, so you'd use model.length
. Every other Qt type related to models or views has a count property: ListModel
, Repeater
, ListView
, etc. So, you could also use rep.count
, in your case.
Generic way is to request repeater for it's underlying model count - in your case it would be rep.count
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With