tags:

views:

248

answers:

1

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)?

+3  A: 

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://doc.trolltech.com/4.5/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. "

brianz
Hah! Brilliant. Knew there had to be a better way to do this. Thank you so much! :)
Mark