View Full Version : remove Widget from QToolBar?

15th July 2010, 02:30
Hi to all!!! :)
i want to know how can i remove widget from QToolbar!!!
ex: ToolBar->addWidget(ComboBox);
i want to remove this ComboBox without using clear function?
please help me!!!
Thanks to all of you !!! :)

15th July 2010, 05:53
Haven't tried it but QWidget::removeAction() with the QAction pointer returned when you added the widget looks promising.

15th July 2010, 06:53
If you simply want to hide the combobox, you may use QAction::setVisible

From the docs -

QAction * QToolBar::addWidget ( QWidget * widget )

Adds the given widget to the toolbar as the toolbar's last item.

The toolbar takes ownership of widget.

If you add a QToolButton with this method, the tools bar's Qt::ToolButtonStyle will not be respected.

Note: You should use QAction::setVisible() to change the visibility of the widget. Using QWidget::setVisible(), QWidget::show() and QWidget::hide() does not work.