How to get a Menu object if you don't know the name?


Hi. I have a request to loop through the existing Menu and be able to wipe them out ((this exists)) but I cannot figure out a way to put each one back if I don’t explicitly have a way to cycle through them.


I’ve setup something like this:

                                {name:"Developer",  action:"remove"},
                                {name:"Tools",      action:"remove"},
                                {name:"Settings",   action:"remove"},
                                {name:"Navigate",   action:"remove"},
                                {name:"View",       action:"remove"},
                                {name:"Display",    action:"remove"},
                                {name:"Avatar",     action:"remove"},
                                {name:"Edit",       action:"remove"},
                                {name:"File",       action:"remove"}

case "remove":
                print('Removing '+menuarray[menu_obj].name+' Menu');

WARNING: if you execute this snippet in a manner that causes you to lose your entire menu bar I am not responsible. :stuck_out_tongue:

Fun fact, if you DO manage to execute this and then hit a the VR Toolbar item it crashes Interface.

So this is a bug, but also I would like to have answered the question above. Anyone?

Here’s what you get to work with…

Menu.addActionGroup(QString,QStringList,QString) function
Menu.addMenu(QString) function
Menu.addMenu(QString,QString) function
Menu.addMenuItem(MenuItemProperties) function
Menu.addMenuItem(QString,QString) function
Menu.addMenuItem(QString,QString,QString) function
Menu.addSeparator(QString,QString) function
Menu.closeInfoView(QString) function
Menu.destroyed() function
Menu.destroyed(QObject*) function
Menu.isInfoViewVisible(QString) function
Menu.isMenuEnabled(QString) function
Menu.isOptionChecked(QString) function
Menu.menuExists(QString) function
Menu.menuItemEvent(QString) function
Menu.menuItemExists(QString,QString) function
Menu.objectName string
Menu.objectNameChanged(QString) function
Menu.removeActionGroup(QString) function
Menu.removeMenu(QString) function
Menu.removeMenuItem(QString,QString) function
Menu.removeSeparator(QString,QString) function
Menu.setIsOptionChecked(QString,bool) function
Menu.setMenuEnabled(QString,bool) function
Menu.triggerOption(QString) function



cc: @MissLiviRose, or anyone that can answer this?


Perhaps a pair of “Menu.hideMenu()” and “Menu.showMenu()” functions would help if they were added to the API.


I wish I could mark this as ‘solved’ because that would be a fantastic way to accomplish what I need. Essentially, I’m not certain how to loop the currently available menu items. Does such a collection, array, or ENUM even exist exposed to the Script layer?


It doesn’t look like there’s a JavaScript API method that exposes the set of menus / menu items.

However, Interface uses Qt’s QMenuBar which has an actions() method that returns a list of top-level menu items, and theses can be recursed through with further acctions() calls to get all menu items. Interface C++ code already uses these methods in places, for example see Menu::scanMenuBar() and Menu::ScanMenu() in Menu.cpp. It should be possible in theory to add a JavaScript API call or two that provides list(s) of menus and menu items.


That will do nicely David. Thank you very much!

For other JS folks out there; the C++ struggle is real. :blush: