Use the Repeater element to Create a Listmodel with various ListElements
-
Hi,
I hope someone can Help me. I have a ListModel and I want to fill it automatically with
ListElements. All the ListElements have a name and an info property. I also have two Arrays that store the name and info values.
Is there a way to do this? maybe by using the Repeater?Thanks in Advance for helping me.
-
Hi,
I hope someone can Help me. I have a ListModel and I want to fill it automatically with
ListElements. All the ListElements have a name and an info property. I also have two Arrays that store the name and info values.
Is there a way to do this? maybe by using the Repeater?Thanks in Advance for helping me.
-
@smeik why do you want to do that?
You can use your arrays directly as models without ListModel, they won't have any roles though.
-
@smeik why do you want to do that?
You can use your arrays directly as models without ListModel, they won't have any roles though.
-
@smeik something like this :
ListView { model: [ { foo: "hello", bar: "red" }, { foo: "world", bar: "orange" } ] delegate: ItemDelegate { text: modelData.foo color: modelData.bar } }Alternatively you could use JsonListModel from https://github.com/benlau/qsyncable if you want to transform a js array to a proper QAbstractListModel
JsonListModel { id: myModel source: [ { foo: "hello", bar: "red" }, { foo: "world", bar: "orange" } ] } ListView { model: myModel delegate: ItemDelegate { text: model.foo color: model.bar } }