[PyQt] QWidget call other __init__ methods, but why?

Barry Scott barry at barrys-emacs.org
Tue Jun 28 16:52:33 BST 2016

Here we have a class that I use in my app. I just fixed a bug
where wbTrackedModeless.__init__ was called twice as proved
by using traceback.print_stack().

class WbTrackedModelessQWidget(QtWidgets.QWidget, WbTrackedModeless):
    def __init__( self ):
        QtWidgets.QWidget.__init__( self, None ) # line 50
    def closeEvent( self, event ):
        WbTrackedModeless.closeEvent( self, event )

        super().closeEvent( event )

From the definition it looks like wbTrackedModeless.__init__ is 
not called.

However here is the stack:

  File "wb_scm_main.py", line 21, in <module>
    sys.exit( wb_main.main( wb_scm_app.WbScmApp, sys.argv ) )
  File "/Users/barry/wc/git/scm-workbench/Source/Common/wb_main.py", line 52, in main
    rc = app.exec_()
  File "/Users/barry/wc/git/scm-workbench/Source/Git/wb_git_ui_actions.py", line 172, in treeTableActionGitLogHistory
    self.main_window.callTreeOrTableFunction( self.treeActionGitLogHistory, self.tableActionGitLogHistory )
  File "/Users/barry/wc/git/scm-workbench/Source/Scm/wb_scm_main_window.py", line 617, in callTreeOrTableFunction
    return fn_tree()
  File "/Users/barry/wc/git/scm-workbench/Source/Git/wb_git_ui_actions.py", line 347, in treeActionGitLogHistory
    self.main_window.getQIcon( 'wb.png' ) )
  File "/Users/barry/wc/git/scm-workbench/Source/Git/wb_git_log_history.py", line 162, in __init__
  File "/Users/barry/wc/git/scm-workbench/Source/Common/wb_tracked_qwidget.py", line 50, in __init__
    QtWidgets.QWidget.__init__( self, None )
  File "/Users/barry/wc/git/scm-workbench/Source/Common/wb_tracked_qwidget.py", line 29, in __init__
  File "/Users/barry/wc/git/scm-workbench/Source/Common/wb_tracked_qwidget.py", line 34, in __trackWidget

This shows that QtWidgets.QWidget.__init__( self, None ) called WbTrackedModeless.__init__()
(__trackWidget is first line of __init__ at line 29).

I guess Phil this is a question for you.

Why does PyQt call __init__ if there is multiple inheritance? Is this a bug in PyQt?


More information about the PyQt mailing list