Details
-
Bug
-
Resolution: Fixed
-
Not Evaluated
-
6.7.1
-
None
-
-
c0674262f (dev), 922aecaef (6.7), 336d79975 (dev), 787b87fe6 (6.7), 04e42efac (tqtc/lts-6.5)
Description
I am porting this code from PyQT5 to implement a simple object list model:
@Property(QQmlListProperty, notify=images_changed) def images(self): return QQmlListProperty(QmlImage, self, self._images)
See https://www.riverbankcomputing.com/static/Docs/PyQt6/qml.html#using-qqmllistproperty
I gave a look to the doc and discovered there is ListProperty described in
https://doc.qt.io/qtforpython-6/examples/example_qml_tutorials_extending-qml_chapter5-listproperties.html
But it seems the only place where ListProperty (append) is documented.
I found the prototype in the code:
ListProperty(QObject, append=None, at=None, count=None, replace=None, clear=None, removeLast=None)
So I tried to use at and count to port my code, but it crashes.
Then I switched to the QAbstractListModel API.
But I noticed data is never called by Repeater and modelData is undefined.
Later I realized that I need to implement a fake roleNames to fix that:
def roleNames(self): return { self.ImageRole: QByteArray(b'image...'), }
Then data is called with role set to this dummy role.
This behaviour looks weird.
To resume:
- Where is the ListProperty documentation ?
- Why PySide doesn't provide the same QQmlListProperty feature than PyQt ?
- QML is looking for QAbstractListModel roles. For some case, it doesn't make sense to implement roles since we can just return an object. In my case, I try to implement a ListModel in the Python side.
- QAbstractListModel seems to implement a fallback under the hood.
Attachments
For Gerrit Dashboard: PYSIDE-2698 | ||||||
---|---|---|---|---|---|---|
# | Subject | Branch | Project | Status | CR | V |
556606,5 | Documentation: Add QtQml.ListProperty | dev | pyside/pyside-setup | Status: MERGED | +2 | 0 |
556931,2 | Documentation: Add QtQml.ListProperty | 6.7 | pyside/pyside-setup | Status: MERGED | +2 | 0 |
558168,5 | PySide: Fix QML ListProperty | dev | pyside/pyside-setup | Status: MERGED | +2 | 0 |
558415,2 | PySide: Fix QML ListProperty | 6.7 | pyside/pyside-setup | Status: MERGED | +2 | 0 |
559582,2 | PySide: Fix QML ListProperty | tqtc/lts-6.5 | pyside/tqtc-pyside-setup | Status: MERGED | +2 | 0 |
559667,1 | PySide: Fix QML ListProperty | tqtc/lts-6.2 | pyside/tqtc-pyside-setup | Status: ABANDONED | -1 | 0 |