Currently I'm working with the QT-framework via PyQT. I have created a custom object (inheriting from QObject) and can use it as expected from QML. I have also created a delegate in QML, which takes care of the visual representation of this object and is also working as expected.
However, now I want to show a list of several of these objects (with the presentation as defined in the delegate) in a ListView (in QML again). I cannot seem to figure out how this is possible, so can someone give me some pointers?
Thanks in advance for your time.
Edit: In response to some reactions I'll try to clarify what I want to achieve a little bit more with an example. Here we have a rectangle (this is just for clarity purposes, normally this would be my custom object) with a single custom attribute (customText) and a delegate which simply defines the layout, both of which are working.
ListView { height: 1000 model: Rectangle { property string customText: "1.jpg" } delegate: Rectangle { width: 200 height: 200 Text { anchors.fill: parent text: model.customText } } } However, now I basically don't want a single rectangle (which wouldn't make a lot of sense in a ListView), but several of them in for example a list. What I would expect is that I would have to change model to something like this, but then I get "Cannot assign multiple values to a singular property ":
model: [Rectangle { property string customText: "1.jpg" }, Rectangle { property string customText: "1.jpg" }, Rectangle { property string customText: "1.jpg" }] Please let me know if you need any further information.
QAbstractListModeland define a model that gives away properties of each of these objects.QAbstractListModelthat holds your data. The properties of theQObjectthat you have created should be transformed intoroles.modelcould be eitherListModel,XmlListModelorVisualItemModel. In your caseVisualItemModelis more suitable for your needs .See this example for more info.