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

QActions instantiated by QUiLoader have the wrong parent

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • P3: Somewhat important
    • 5.12.2
    • 5.12.1
    • PySide
    • None
    • All
    • 78b2438037504ae80eaf6b01d49df9ddb660656a (pyside/pyside-setup/5.12)

    Description

      I use a subclassed QUiLoader which overrides the createAction() method and any QAction instantiated by the createAction() of the QUiLoader superclass has the QUiLoader itself as its parent instead of the parent passed as an argument to the createAction() method. Simply trying to access the QActions's parent via the parent() accessor fixes it, it took me quit a while to figure this out with using shiboken2.dump().

      To illustrate, here is the essential code:

      class UiLoader(QtUiTools.QUiLoader):
      [...]
          def createAction(self, parent=None, name=''):
          print(f'parent: {parent}')
      
          action = super().createAction(parent, name)
      
          print(shiboken2.dump(action))
          print(f'action.parent: {action.parent()}')
          print(shiboken2.dump(action))
      
          if name != '' and not name.startswith('_'):
              setattr(self.ui, name, action)
      
          return action
      

       which produces the following output:

      parent: <xpwm.widgets.main_window.MainWindow object at 0x7f0d10c0e988>
      C++ address....... PySide2.QtWidgets.QAction/0x2d28b40
      hasOwnership...... 0
      containsCppWrapper 0
      validCppObject.... 1
      wasCreatedByPython 0
      parent............ <xpwm.widgets.uiloader.UiLoader object at 0x7f0d0eb4f308>
      
      action.parent: <xpwm.widgets.main_window.MainWindow object at 0x7f0d10c0e988>
      C++ address....... PySide2.QtWidgets.QAction/0x2d28b40
      hasOwnership...... 0
      containsCppWrapper 0
      validCppObject.... 1
      wasCreatedByPython 0
      parent............ <xpwm.widgets.main_window.MainWindow object at 0x7f0d10c0e988>

      Attachments

        Activity

          People

            crmaurei Cristian Maureira-Fredes
            gber gber
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: