I'd like to make class that derives from PyQt5 QtWidget.QWidget
and an abc.ABCMeta
. Both these classes have their own meta class as type so, according to this page and this SO question, I need to create my own meta class that derives from the meta classes of QWidget
and abc.ABCMeta
, and explicitly use that as metaclass for my class.
So far so good, I've defined an QtAbcMeta
class and used this as metaclass
for my ConcreteWidget
class (see below).
import abc
from PyQt5 import QtWidgets, QtCore
class AbstractClass(metaclass=abc.ABCMeta):
def __init__(self, name):
self._name = name
@abc.abstractmethod
def myMethod():
pass
class QtAbcMeta(type(QtWidgets.QWidget), type(AbstractClass)):
pass
class ConcreteWidget(QtWidgets.QWidget, AbstractClass, metaclass=QtAbcMeta):
def __init__(self, name, parent=None):
AbstractClass.__init__(self, name)
QtWidgets.QWidget.__init__(self, parent=parent) # This gives a type error.
def myMethod():
print("My widget does something")
def main():
app = QtWidgets.QApplication([])
myWidget = ConcreteWidget('my name', parent=None)
if __name__ == "__main__":
main()
However, when I try to call the __init__
method of the QtWidgets.QWidget
method, to set the parent, I get the following TypeError:
Traceback (most recent call last):
File "main.py", line 36, in <module>
main()
File "main.py", line 33, in main
myWidget = ConcreteWidget('my name', parent=None)
File "main.py", line 24, in __init__
QtWidgets.QWidget.__init__(self, parent=parent) # This gives a type error.
TypeError: __init__() missing 1 required positional argument: 'name'
I have no idea what's wrong here. Has the signature of QtWidgets.QWidget.__init__
changed somehow? Any help would be appreciated.