Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Show/hide QDockWidget?

Tags:

visibility

qt

I have a dock widget, now I want to add a "Window" menu to show/hide the widget. Easy enough to do with

showPropWinAct = new QAction(tr("&Properties"), this);
showPropWinAct->setStatusTip(tr("Show properties window"));
showPropWinAct->setCheckable(true);
connect(showPropWinAct, SIGNAL(toggled(bool)), propertiesWindow, SLOT(setVisible(bool)));

The problem is when the user clicks the [x] on the widget, the showPropWinAct doesn't get toggled. How can I listen for this event, and toggle the action properly, without firing off a 2nd setVisible signal (one from the close event presumably, and one from the connect above)?

like image 441
mpen Avatar asked Aug 17 '09 20:08

mpen


1 Answers

Instead of creating a new action, simply get the action from the QDockWidget itself and use that. It'll take care of state for you:

http://qt-project.org/doc/qt-4.8/qdockwidget.html#toggleViewAction

QAction * QDockWidget::toggleViewAction () const

"Returns a checkable action that can be used to show or close this dock widget.

The action's text is set to the dock widget's window title. "

like image 169
brianz Avatar answered Sep 20 '22 17:09

brianz