PDA

View Full Version : Available action in main window menu even when dockwidget still doesn't exists



tiredtyrant
20th April 2010, 21:33
I was taking a look at the Dock Widgets example that comes with Qt. It can be found here (http://doc.trolltech.com/4.6/mainwindows-dockwidgets.html).

In MainWindow::createDockWindows() a QDockWidget instance is created and its address is passed to a pointer called 'dock'. The main window has a menu item called 'view' that shows a toggle action to show or hide the available dockwidgets. It adds the toggle item to the menu with this: viewMenu->addAction(dock->toggleViewAction());

Suppose that in another application, a few particular dockwidgets are created at runtime. If i did the same way as the example, the toggle items for each particular dockwidget would only show in the viewMenu after they are created, but I'd like to have them exist even when the dockwidget itself haven't been created yet. The item in the viewMenu would be inert, but would work after the dockwidget is created. How can I do that?

Lykurg
20th April 2010, 21:59
Well, then you have to create your own toggle-able action and connect it to the dock widget when it is created. Signal toggled(bool) and slot setVisible().

tiredtyrant
20th April 2010, 22:27
It worked, thanks!