Skip to content
Advertisement

Using ListModel (Python/Pyside6) in QML

I have a ListView in QML and want to populate it with data from a AbstractListModel that I created in Python.

AbtractListModel.py (I removed methods like rowCount() to keep the example lucid)

JavaScript

Student.py

JavaScript

ListView.qml

JavaScript

How can I access name and age of a student in the delegate to show them where I used “#name” and “#age”?

Advertisement

Answer

At a minimum you must implement the rowCount, data and roleNames methods of the QAbstractListModel:

JavaScript
JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement