QQmlListProperty in PySide2
-
Hi, I'm fairly new to QML, but have been using Qt widgets in C++ and Python since Qt4.x.
I'm currently interested in using QML with the official PySide2 bindings to create new and extend existing QML types. In order to learn how to do this I've been trying to convert the official examples (https://doc.qt.io/qt-5/qtqml-tutorials-extending-qml-example.html) from C++ to Python.
I've gotten to tutorial 5, where they start to use QQmlListProperty, but that class doesn't seem to currently exist in the PySide2 bindings (https://wiki.qt.io/Qt_for_Python_Missing_Bindings#QtQml). Is there currently a preferred workaround for this? I've done some experimenting with QAbstractListModel and had a working example using that, but I'm just trying to discover the limitations of the current PySide2 bindings. I'm using PySide2 version 5.14.1.
-
I just stumbled on the same stone ;-).
A cursory search in qt bug database shows that it will be missing with the current version of shiboken ( see https://bugreports.qt.io/browse/PYSIDE-958?jql=text ~ "QQmlListProperty")
Interestingly there is a reference to a probable bypass via a PySide2.QtQml.ListProperty function, but i've only found it -incompletely. documented for v1 (a sample at https://code.qt.io/cgit/pyside/pyside-setup.git/tree/sources/pyside2/tests/QtQml/registertype.py)
Some test i made give me following acceptable signature
tree = ListProperty(PythonType/Class,append=func,at=func,clear=func,count=func)I'm just pondering to explore the route, or switching to PyQt5 which does implement the class, but is not LGPL but pure GPL ....
-
I believe what you are looking for is described in this example:
You want to use
ListProperty
in Python for this. It takes the same parameters as the C++ side does, so referring to the C++ docs for this is helpful.