Uploaded image for project: 'Qt for Python'
  1. Qt for Python
  2. PYSIDE-2698

ListProperty / QAbstractListModel usage for object list model

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • Not Evaluated
    • 6.5.6, 6.7.1
    • 6.7.1
    • Documentation
    • None
    • All
    • 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

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            shpremna Shyamnath Premnadh
            fabricesalvaire fabrice salvaire
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes