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!

James
  • 3,682
  • 3
  • 22
  • 21

1 Answers1

34

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

QAction* widgetAction = toolBar->addWidget(someWidget);
widgetAction->setVisible(false);
richardwb
  • 4,339
  • 33
  • 19
  • 1
    Thanks, didn't notice it returned a QAction on the addWidget! So much for knowing how to read simple API docs. – James Nov 08 '09 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 '16 at 01:14
  • What a convoluted API decision. – dev_nut Dec 04 '18 at 00:42