Results 1 to 5 of 5

Thread: How to get a menu or action by name or by numbers ?

  1. #1
    Join Date
    Sep 2010
    Posts
    654
    Thanks
    56
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default How to get a menu or action by name or by numbers ?

    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

  2. #2
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: How to get a menu or action by name or by numbers ?

    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.

  3. #3
    Join Date
    Sep 2010
    Posts
    654
    Thanks
    56
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to get a menu or action by name or by numbers ?

    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

  4. #4
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: How to get a menu or action by name or by numbers ?

    Don't know if this will help you, but for every menu, you can get a list of it's actions by calling:
    Qt Code:
    1. QList<QAction*> actions = menu->actions();
    To copy to clipboard, switch view to plain text mode 

    QMainWindow menus created in designer are held in QMenuBar, maybe you can get list of all menus inserted in menu bar by "findChildren" method:
    Qt Code:
    1. QList<QMenu*> menus = mainWindow->menuBar()->findChildren<QMenu*>();
    To copy to clipboard, switch view to plain text mode 

    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.

  5. #5
    Join Date
    Sep 2010
    Posts
    654
    Thanks
    56
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to get a menu or action by name or by numbers ?

    Thanks stampede

Similar Threads

  1. Menu item action problem
    By waynew in forum Newbie
    Replies: 5
    Last Post: 15th December 2010, 00:42
  2. Menu open action -reg
    By jsmith in forum Qt Programming
    Replies: 1
    Last Post: 8th May 2009, 12:07
  3. Action-Menu-Button
    By hgedek in forum Newbie
    Replies: 1
    Last Post: 1st October 2007, 17:41
  4. ToolBar Action With Menu
    By indifference in forum Qt Programming
    Replies: 4
    Last Post: 10th September 2007, 20:37
  5. Action on menu to display ui
    By jochen_r in forum Newbie
    Replies: 10
    Last Post: 10th January 2006, 11:10

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.