Question: Hello~ I'm creating a set of custom widgets that extend the native widgets in Qt. My custom widgets are supposed to be constructed from a data source, and they all provide a custom function Foobar. For example: class CheckBox: public QCheckBox, public Control { Q_OBJECT public: CheckBox(QWidget* parent = 0); CheckBox(DataSource* data, QWidget* parent = 0); virtual ~CheckBox(); virtual void Foobar(); }; class ComboBox: public QComboBox, public Control { Q_OBJECT public: ComboBox(QWidget* parent = 0); ComboBox(DataSource* data, QWidget* parent = 0); virtual ~ComboBox(); virtual void Foobar(); };  Each widget class has a corresponding data source class that is responsible for creating the widget. For example: class CheckBoxDataSource: public DataSource { public: CheckBoxDataSource(); virtual ~CheckBoxDataSource(); virtual QWidget* createControl(QWidget* parent); }; class ComboBoxDataSource: public DataSource { public: ComboBoxDataSource(); virtual ~ComboBoxDataSource(); virtual QWidget* createControl(QWidget* parent); };  After these classes are exposed to Python, Python clients who have a list of various data sources are expected to use it like this: for data in dataSources: widget = data.createControl(parent) # returns a QCheckBox/QComboBox/etc # at a later time ... widget.Foobar()  However, this is not going to work because data.createControl() will return an object of type QCheckBox or QCombox in PyQt, so clients won't be able to call widget.Foobar() as the Foobar() function isn't available in these classes. How can I work around this? So far I have tried these below but none of them works... Attempt 1 In Python, I tried casting the widget to the right C++ class so that I can call Foobar(). widget.__class__ = CheckBox widget.__class__ = ComboBox  In some cases this works fine, in other cases I get an error AttributeError: 'CheckBox' object has no attribute 'Foobar' even though it's the correct type. Interestingly, if I put a breakpoint on the line and steps over it in the debugger, it always works, without the breakpoint it fails, so there seems to be a timing issue that I could not figure out. Anyway, mutating __class__ is dangerous so I probably should avoid it. Attempt 2 If I add virtual void Foobar() to the base class Control and declare createControl() to return a Control* instead of QWidget*. This should allow clients to call Foobar() in Python, but they also lose the ability to treat it as a QWidget. Attempt 3 widget = CheckBox(data.createControl(parent))  By wrapping the returned object in another constructor call, the widget in Python should now have the right type. But this will create 2 CheckBox widgets, not 1, so I have to "delete" one of them. Looks like the copy constructor is being called in this case. I don't think I can move it in Python. Sorry my brain is a huge mess at the moment, I think there should be a better factory design?

Answer: So you want to have QWidget*s with additional interface Foobar. I am afraid it might not be possible, not in a straightforward C++ way, without wrapper classes, e.g. similar to setupUi(parentPtr); pattern used by Qt User Interface Compiler . Qt doesn't allow multiple inheritance from QObject, so you cannot design your class Control to be a QWidget, because then you cannot inherit both Control and QCheckBox. However, you can use the MetaObjects features (Reflection pattern). If you define your additional interfaces as QINVOKALBES: class MyCheckBox : public QCheckBox { Q_OBJECT; public: Q_INVOKABLE void Foobar() { qDebug() << "MyCheckBox::Foobar"; } };  you can then call them with QMetaObject::invokeMethod(myCheckBoxPtr, "Foobar", Qt::DirectConnection); where myCheckBoxPtr is QWidget* (or even QObject* if you want to abstract further). C++ documentation, python documentation