PDA

View Full Version : Runtime application menu customisation



oberlus
26th July 2011, 18:01
Hi,

I'd like to find out if it is possible to implement using Qt something similar to the way some MS apps (eg VS 2008, Outlook 2007) provide in terms of modifying the application menus at runtime, in terms of adding/removing/moving menu entries.

These apps typically provide this functionality in Tools->Customize... which once selected causes a list of available commands to be displayed and also places the application menus in an editable mode allowing you to re-arrange items or drag and drop items from the list of commands to the menus, etc. Once the changes have been applied the app saves the GUI state/layout to be loaded the next time it is started.

I'm not referring to generating the list of available commands, which would be quite application specific, but to the way the app lets you re-arrange ad modify its menus.

Does anyone have any experience doing this with Qt or could suggest an alternative scheme that has worked well in the past? Are there any hight level classes or toolkits to do this?

Thx.

mcosta
26th July 2011, 18:30
In Qt menu and toolbars entries are QAction instances.

Using QWidget::actions() you can retrieve the list of actions of the widget (QMenu, QToolBar) and using QWidget::addAction() / QWidget::removeAction() you can manage them.

You could then:

load all actions of QMainWindow with findChildren()
load all menu
create a GUI to manage them
use the new configuration to set actions for each menu