View Full Version : QMenuBar Updates

19th January 2010, 17:50
I am trying to update the menu bar for different mdi windows. To do that, I tried to step down the menu tree, removing old QMenu items by removing the action from the QMenuBar, and replacing them using insertMenu(). However, the inserted menu does not appear in the QMenuBar action list, leading to later failure.

Starting over, using QMenu::clear() also deletes all the owned actions unless they are used elsewhere. In order to be careful and avoid failure modes at close(), the entire menu bar, toolbar, menus, actions and connections seem to need rebuilding at every new subwindow or every change within a subwindow. Is this as it seems or did I miss something?

19th January 2010, 22:55
Save pointers to your QActions (menuitems) and update them. Do not remove and action and add another action with a different caption but just call setText to update the text in the menu. (Assumption: Menu-layout is the same for all child-windows).

19th January 2010, 23:31
To be more explicit, the menus for each child can be different; the children have a stacked widget and each page of the stacked widget can have a different menu. I have saved pointers to the actions in the children, but I was uncertain if removing the action from the menu bar would delete them. (Do saved pointers keep the instantiation from being destroyed once it is removed from the parent?)

I have since rebuilt the menu bar at every change of subwindow, or stacked widget index, and that works. While I'm sure a merge should be possible, the code was more traceable that way. Thanks for your help.

19th January 2010, 23:35
It is safe to remove an action from a menu. The idea behind the action is that the same action can be accessed at multiple positions in the GUI, for example in a menu as well as in a toolbar.

You are not trying to duplicate the SAP-GUI do you? Changing the menubar during runtime is considered bad usability behaviour.

20th January 2010, 13:49
My confusion I guess. I've used another framework (MFC) for awhile. In that framework, child windows can merge menus with the main menu. To give an example, suppose the main menu is [File, Window, Help] and, the child window brings up a plot of data. The child window has its own menu, [Graphics], which is then merged to yield [Main, Graphics, Window, Help]. Then the user switches the child window to a table with its own [Edit] menu. The [Graphics] menu is removed and the main menu is merged with the new child menu to give [Main, Edit, Window, Help]. Is this the menu behavior that is in disfavor?

Sorry, I don't know the SAP-GUI, having never used it. But I do have an existing application that I am rebuilding in QT. It currently has 16 different children, with 10 different models or proxies, and as many submenus. Further, our users have asked for 4 more functions, and we will implement those in 4 more children with varying submenus. What is the proper way to address that need? I hadn't known of any other menuing design.

BTW, thanks for you help with the action removal. I wasn't sure how reference counts were being done; the parent might have assumed the reference of the child.

20th January 2010, 14:35
Unfortunately, you have to reimplement that behaviour in Qt. There is no menubar merging feature available.

The bad behaviour is that during runtime, the menubar changes. It is ok as long as you preserve File/Edit/Help and so an. Bad would be if you invoke one Dialog, the menubar changes to something completely different and the user sees no way back.