Чем отличается qwidget от qmainwindow
Перейти к содержимому

Чем отличается qwidget от qmainwindow

  • автор:

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?

12.5k 12 12 gold badges 50 50 silver badges 85 85 bronze badges
asked Jul 24, 2014 at 7:21
121 3 3 silver badges 10 10 bronze badges

2 Answers 2

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.

4,305 3 3 gold badges 25 25 silver badges 30 30 bronze badges
answered Jul 24, 2014 at 7:38
1,416 16 16 silver badges 37 37 bronze badges

i have solved in this mode:

the first class, Widget.h:

#ifndef WIDGET_H #define WIDGET_H #include #include #include namespace Ui < class Widget; >class Widget : public QWidget < Q_OBJECT public: Widget(QWidget *parent = 0); virtual ~Widget(); QPushButton *getBtn() const; void setBtn(QPushButton *value); protected: void mousePressEvent(QMouseEvent *evt); void mouseMoveEvent(QMouseEvent *evt); private: Ui::Widget *ui; QPushButton *btn; QPoint oldPos; >; 

and the second class widExt.h, that inherit from Widget:

#ifndef WIDEXT_H #define WIDEXT_H #include "widget.h" namespace Ui < class widExt; >class widExt : public Widget < public: widExt(); private slots: void on_dial_2_actionTriggered(int action); private: Ui::widExt *ui; >; #endif // WIDEXT_H 

with the relative widExt.cpp:

#include "widext.h" #include "ui_widext.h" widExt::widExt() : ui(new Ui::widExt) < ui->setupUi(this); > void widExt::on_dial_2_actionTriggered(int action)

in this mode, i inherit all from the first class and i can customize other classes independently.

Добавить комментарий

Ваш адрес email не будет опубликован. Обязательные поля помечены *