20

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!

1 Answer 1

35

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

QAction* widgetAction = toolBar->addWidget(someWidget);
widgetAction->setVisible(false);
3
  • 1
    Thanks, didn't notice it returned a QAction on the addWidget! So much for knowing how to read simple API docs.
    – James
    Nov 8, 2009 at 16:01
  • Haha. I googled around for this problem and came upon this answer. I had already +1ed the question and answer some time back, but I had forgotten over time. I'd +2 if I could. :-)
    – metal
    Sep 10, 2016 at 1:14
  • What a convoluted API decision.
    – dev_nut
    Dec 4, 2018 at 0:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.