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)?
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. "
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With