Details
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
For Gerrit Dashboard: PYSIDE-938 | ||||||
---|---|---|---|---|---|---|
# | Subject | Branch | Project | Status | CR | V |
253624,4 | Set proper parent when overloading QUiLoader | 5.12 | pyside/pyside-setup | Status: MERGED | +2 | 0 |