PDA

View Full Version : Dock Widget problems



dbrmik
17th April 2009, 10:38
Hi

I have a main window with a dock widget. The dock widget is initially hidden. It is displayed when the user selects the action from a menu (same as dock widgets example), this works fine.

I also have an icon on a toolbar to control the visibility of the same dock window. I want to be able set enable/disable the icon depending on the visibility of the dock window. How can I achieve this (ideally I would like the menu item and icon controlling the visibility of the dock window to be synchronized)

Thanks

munna
17th April 2009, 10:58
You can use the same QAction for both the menu and the toolbar.

Lykurg
17th April 2009, 11:00
Ok, you have a Q<Menu>Action, Q<Toolbar>Action and the QDockWidget. Only connect the Q<Menu>Action to the QDockWidget. (toogle -> setVisible). and then connect the Q<Menu>Action with the Q<Toolbar>Action (toggled -> setChecked) and vice versa.

Or use QDockWidget::toggleViewAction() direct as an action in your menu.

Lykurg

dbrmik
17th April 2009, 11:20
Hi

Thanks

I am using toggleViewAction to populate the menu. How do I use it to control the icon state in my toolbar?

Lykurg
17th April 2009, 11:36
QAction toolbaraction = new QAction(...);
QAction act = QDockWidget::toggleViewAction();
QMenu::addAction(act);
connect(act, SIGNAL(toggled(bool)), toolbaraction, SLOT(setChecked(bool)));
connect(toolbaraction, SIGNAL(toggled(bool)), act, SLOT(setChecked(bool)));

if you want to have different icons etc in menu and toolbar. If not just use the same action as munna has mentioned

dbrmik
17th April 2009, 12:39
Thanks Lykurg & munna for your help :D