I am working on a project involving PyQt5, and I am struggling with managing inheritance between widgets.
I have one QWidget screen that inherits off QtWidgets.QWidget and another class which is generated by QtDesigner. It reads something like this:
class a(QtWidgets.QWidget, Ui_a):
def __init__(self, parent=None):
QtWidgets.QWidget.__init__(self, parent)
self.setupUi(self)
<some attributes>
<some functions
Here, I inherit off Ui_a
, a separate class stored in a generated file, and I can call setupUi
(a method of Ui_a
) fine.
I now want to create another class b
, which also is a QWidget that needs to be displayed. This class b
requires the use of some of the functions and attributes from class a
. I can easily just copy paste the required stuff in but that is bad practice so I am looking for a more neat solution. If I do the code:
class b(QtWidgets.QWidget, Ui_b, a):
def __init__(self, parent=None):
QtWidgets.QWidget.__init(self, parent)
self.setupUi(self)
This then crashes with an error message saying that it cannot create a consistent method resolution order.
My first question is - I know I need to call the init method of class a
since a
's attributes are created there, but I don't know how.
My second question is - How do I fix this MRO error and succeed in creating the new class b
which can use a
's attributes and functions?