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

QGraphicsItem.parentItem() fails when parent has __getitem__ defined

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • P3: Somewhat important
    • None
    • 5.9
    • PySide
    • ubuntu 17.10 + anaconda + PySide wheel 5.9.0a1.dev1525349078

    Description

      When using subclasses of QGraphicsItem, I have found that defining _getitem_ on a subclass will cause parentItem() to fail on a child item. For example:

       

      from PySide2.QtWidgets import QGraphicsItem, QGraphicsRectItem
      
      class GraphicsItem(QGraphicsItem):
          def __getitem__(self, item):
              return None
      
      parent = GraphicsItem()
      child = QGraphicsRectItem(parent)
      
      print("Parent:", child.parentItem())

      Running the above code generates the following error:

       

      Traceback (most recent call last):
        File "<stdin>", line 1, in <module>
      TypeError: object of type 'GraphicsItem' has no len()

      The above example might seem contrived, but it was the result of about an hour of stripping down a larger application until it became clear what the problem was. So although the solution here is simple (remove _getattr_ from parent class), it is not at all obvious when this is encountered in a real application, and the result is very difficult to debug.

      Attachments

        For Gerrit Dashboard: PYSIDE-671
        # Subject Branch Project Status CR V

        Activity

          People

            crmaurei Cristian Maureira-Fredes
            lcampagn Luke
            Votes:
            1 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes