pyQt4 and inheritance

前端 未结 1 681
礼貌的吻别
礼貌的吻别 2021-01-07 06:13

For a number of reasons I am contemplating redoing an program I use at work in pyqt4 (at present it is in pygtk). After playing around with it and getting a feel for it and

相关标签:
1条回答
  • 2021-01-07 06:46

    This is not a QT issue, but a lack of understanding of how multiple inheritance works. You can absolutely use multiple inheritance, but it is a tricky subject in Python.

    In a nutshell, in your last example, the first __init__ is called, so if you changed class D(QtGui.QMainWindow,A): to class D(A, QtGui.QMainWindow): you would see A's constructor called, and not QMainWindow's one.

    See the following links for further reference on super() behavior with multiple inheritance:

    • How does Python's super() work with multiple inheritance?
    • http://python-history.blogspot.com/2010/06/method-resolution-order.html
    0 讨论(0)
提交回复
热议问题