PDA

View Full Version : How to get a menu or action by name or by numbers ?



tonnot
16th February 2011, 10:28
I would to get (for example) the menu "mymenu" or menu[0] and separators and actions...
How can I navigate trought them?
The final goal is to deal with menus.
Thanks

stampede
16th February 2011, 12:22
I think your question could not be less descriptive. Seriously, try to read it and imagine that you don't know anything about your problem.

From what I could deduce, you want to create some kind of a container with menus in order to access them by index or name ?
If yes, then create a QList of menus ( for index based access ) or a QMap<QString,QMenu*> ( for name based access ), then you could get something like:

QMenu * m = menu_map["main menu"];

But I don't see a reason for doing this. Can you provide more detailed description of your problem ? Maybe there is a better solution.

tonnot
16th February 2011, 13:30
Thanks, and sorry for my bad comunication ....
Yes, I want to work with menus using its name or index.
Is there any method to get the whole menu of my app?
I want to work with the menu made in design....

Thanks again

stampede
16th February 2011, 14:24
Don't know if this will help you, but for every menu, you can get a list of it's actions by calling:

QList<QAction*> actions = menu->actions();

QMainWindow menus created in designer are held in QMenuBar, maybe you can get list of all menus inserted in menu bar by "findChildren" method:

QList<QMenu*> menus = mainWindow->menuBar()->findChildren<QMenu*>();

Be sure to read documentation for above methods before using them.
Still, I don't know what do you want to do with such lists.

tonnot
16th February 2011, 15:46
Thanks stampede