Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why cant a QToolButton be hidden after it is added to a QToolBar?

This works...

QToolButton * toolbutton = new QToolButton(this);

//hide before addWidget
toolbutton->hide();

addWidget(toolbutton);

But this doesn't

QToolButton * toolbutton = new QToolButton(this)

addWidget(toolbutton);

//hide after addWidget
toolbutton->hide();

Is there an alternative so I can actually hide after a QToolButton after it is added to a QToolBar? I need to during runtime.

like image 974
Geore Shg Avatar asked Sep 17 '25 23:09

Geore Shg


2 Answers

QAction * QToolBar::addWidget ( QWidget * widget )

You should hide returned QAction

like image 173
Kamil Klimek Avatar answered Sep 20 '25 15:09

Kamil Klimek


One alternative is to add a QAction instead of a widget and then hide the QAction. I've tried it and it works with QAction::setVisible(false).

You can also do something like QToolBar::actions().at(3)->setVisible(false); if you know the position of the widget in the QToolBar.