views:

70

answers:

2

Hi,

I have created a menu bar and some menus with Qt creator. One of the menus had to be coded to use QActionGroup features. Now it is easy to add my custom menu to the menu bar with:

printMenu = menuBar()->addMenu(tr("&Print"));

but my menu will be in the last position of the menu bar. How do I add my menu at a specified place? (e.g. the second place right after the File menu)

Greetings

+4  A: 

Use QMenuBar::insertMenu.

Job
A: 

If you want to add a sub menu in the middle of the menubar, this is not trivial. There is no direct API to do this but you can probably pull that out byt manipulating the internal actions of QWidget (QMenu::addMenu just calls QWidget::addAction(menu->menuAction()).

In theory, you can manipulate QMenuBar::actions(), but I never did it.

When I had to do handle this problem, I just reconstructed the menu from another dataset (look in your favorite search engine for qmdilib and you will see my solution).

elcuco
Thanks for your answer, it helped me a lot!
walki
Please explain why did you vote down, this helps me give better answers or learn. Thanks.
elcuco