Search code examples
c++qtqt5qwidget

QWidget inherit from custom QWidget


In Qt C++, is it possible to create a custom QWidget and then reuse this custom QWidget for all QWidget (that inherit all from the custom QWidget) of the project?


Solution

  • Maybe I have misunderstood the question, but you can just create your custom QWidget, then use it everywhere.

    class derivedQWidget : public QWidget
    {
      Q_OBJECT
    
      derivedQWidget();
      virtual ~derivedQWidget();
    }
    
    class myWidget : public derivedQWidget 
    {
      ...
    }
    
    class myWidget2 : public derivedQWidget 
    {
      ...
    }
    

    If the question is: Can we reimplement QWidget?, no you can't.