[PyQt] Newbie's question about inheritance in QtPy4 classes

Igor pesando ipesando at gmail.com
Wed Aug 18 20:15:20 BST 2010

Hi all,

sorry to bother but I'm learning PyQt4 and  designer.
Playing with the code suggested in some tutorials I came with the code below
which should NOT work according to my understanding of inheritance but it works.
The problem is that the class MyForm inherits from QMainWindow which
does not inherit from QDockWidget even if they both inherit from
Therefore QtGui.QDockWidget.__init__(self, parent)  should fail but
everything works fine.
As a matter of fact  I tried a similar construction within plain
python and I get an error message.
So the question is why QtGui.QDockWidget.__init__(self, parent) works?

import sys
from PyQt4 import QtCore, QtGui

class MyForm(QtGui.QMainWindow):
    def __init__(self, parent=None):
        QtGui.QDockWidget.__init__(self, parent)

if __name__ == "__main__":
    app = QtGui.QApplication(sys.argv)
    myapp = MyForm()

Thanks in advance

Igor P

More information about the PyQt mailing list