Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hiding a QWidget on a QToolbar?

Tags:

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!

like image 504
James Avatar asked Nov 07 '09 21:11

James


People also ask

What is a qtoolbar widget?

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.

What is the use of M_hiddenwidget in qtabwidget?

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.

How to make a qwidget a window?

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).

How to add a toolbar to a qmainwindows widget?

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.


1 Answers

You need to call setVisible() on the appropriate QAction instead. For example, addWidget() returns a QAction*:

QAction* widgetAction = toolBar->addWidget(someWidget);
widgetAction->setVisible(false);
like image 86
richardwb Avatar answered Oct 04 '22 14:10

richardwb