QMenu in a base class
Unsolved
General and Desktop
-
Hello!
I have this base class, implemented by other classes:
#ifndef ABSTRACTQWIDGET_H #define ABSTRACTQWIDGET_H #include <QWidget> #include <QMenu> #include <QTableWidget> #include <QLineEdit> #include <QMenuBar> #include "savetable.h" class AbstractQWidget : public QWidget { Q_OBJECT public: AbstractQWidget(QWidget *parent = nullptr) : QWidget(parent) {} virtual ~AbstractQWidget() = 0; protected slots: virtual void setToUpper(const QString &text) = 0; virtual void saveTable() = 0; protected: void toUpper(const QString &text) { QLineEdit *qle = qobject_cast<QLineEdit *>(sender()); if (!qle) return; qle->setText(text.toUpper()); } void exportTable(QString strFile, QTableWidget *tbl) { SaveTable st(strFile, tbl); } }; #endif // ABSTRACTQWIDGET_H
I would like to create a common menu for all classes that extend this.
how can I do? -
Hi,
You can either create a protected member variable that you will access from the subclass or make it private and create protected functions to manipulate it from the subclasses.
-
hi!
thanks for the reply.
looking on google, I read that it would be better to use QMainWindow instead of QWidget.
I think I'll use that, it seems to me easier. -
- Create your own QToolBar object inside your base class. Add the required action to it.
- Create the verticalLayout and apply the same to your base class widget. Add the toolbar widget to to verticalLaoyout.
- Give public method inside your base class for the user add any widget if he wants.
- Inside the method you should add the widget to vertical layout.
Hope this helps.