I have directly added some QWidgets to a QToolbar but simply going widget->setVisible(false) did not work. Can someone please give me an example of how to show and hide a widget that is on a QToolbar?
Thanks!
A QToolBar widget is a movable panel consisting of text buttons, buttons with icons or other widgets. It is usually situated in a horizontal bar below menu bar, although it can be floating.
Each tab in the QTabWidget is a QWidget that contains other widgets. In my example m_hiddenWidget is a QWidget and it keeps all widgets that are in the current widget like edit lines and the labels. At the begging m_hiddenWidget is nullptr I use it to keep the content of a hidden tab between remove and insert.
Every widget's constructor accepts one or two standard arguments: QWidget *parent = nullptr is the parent of the new widget. If it is nullptr (the default), the new widget will be a window. If not, it will be a child of parent, and be constrained by parent 's geometry (unless you specify Qt::Window as window flag).
To easily place the toolbar in your widget use its layout manager, e.g.: As for the second question: you can have as many QMainWindows as you want. They are nothing more than a specialized QWidget, just like any other. You can nest them as you wish too.
You need to call setVisible()
on the appropriate QAction instead. For example, addWidget()
returns a QAction*:
QAction* widgetAction = toolBar->addWidget(someWidget);
widgetAction->setVisible(false);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With