Question

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.

Was it helpful?

Solution

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.

OTHER TIPS

QAction * QToolBar::addWidget ( QWidget * widget )

You should hide returned QAction

toolbar->actions().at(0)->setVisible(false);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top