0

I am a beginner at Qt and QML. I am writing an application in python (PySide6) and I can't figure out if I can use a single object as a model? There are plenty of resources on how to use ListModels which, as the name suggests, contain multiple objects in a list. you can usually do something like this:

ListView {
    anchors.fill: parent
    model: myModel  // defined in py or c++ class
    delegate: Text {
        text: model.display
    }
}

My question is: Is there any way you can do something like that with a SINGLE object, not a list of objects? Can you please point me towards a QML class that could do that or any useful resources? My only goal is to connect a single object from my python code to the QML file.

EZbrute
  • 400
  • 2
  • 14
  • I guess that the [documentation](https://doc.qt.io/qt-5/qtquick-modelviewsdata-modelview.html#qml-data-models) is pretty clear. – folibis May 09 '22 at 14:13
  • You can make a ListModel with only one item in it. But what's the point of using a ListView with only one item? Are you actually looking for a [Loader](https://doc.qt.io/qt-5/qml-qtquick-loader.html)? – JarMan May 09 '22 at 14:13
  • The documentation was NOT clear, but I found a [different](https://stackoverflow.com/questions/50609986/how-to-connect-python-and-qml-with-pyside2) SO question that was helpful enough. – EZbrute May 09 '22 at 14:36

0 Answers0