October 10, 2011

Luca Luca
Ant Farmer
590 posts

[Solved] QMenuBar && menu’s order

 

Hi all,
I have a QMainWindow with it’s menubar.
In the mainWindow contructor I add two menus (File, help) .

When users login in a QDialog I need to add some other menus in the menubar after the “File” menu and before the “Help” menu.

Ho can I do without deleting and re-adding all menus?

6 replies

October 10, 2011

Andre Andre
Area 51 Engineer
6067 posts

Well, you could always try QMenuBar::insertMenu()…

 Signature 

Looking for Qt developers to join our team @ i-Optics: https://qt-project.org/forums/viewthread/25393/

October 10, 2011

Luca Luca
Ant Farmer
590 posts

Thanks Andre,
I didn’t see insertMenu(). I was looking for addSomething(…, int pos) … :-)

October 10, 2011

Andre Andre
Area 51 Engineer
6067 posts

This is a pattern in Qt. In the Qt API, add appends at the end, and insert somewhere in the middle. Keep an eye out for it, you’ll spot it everywhere it makes sense :-)

 Signature 

Looking for Qt developers to join our team @ i-Optics: https://qt-project.org/forums/viewthread/25393/

October 10, 2011

Luca Luca
Ant Farmer
590 posts

I’m trying

  1. QMenuBar::insertMenu ( QAction * before, QMenu * menu )

but I don’t undertand very well what is :

  1. QAction * before

I need to insert the new menu after or before another menu in the menubar, not before an action…

October 10, 2011

Volker Volker
Robot Herder
5428 posts

insertMenu() and addMenu() return a QAction pointer which can be used as the first argument. You will have to save the pointer though.

October 11, 2011

Luca Luca
Ant Farmer
590 posts

Ok, I solved inserting the “Help” menu too with insertMenu() instead of addMenu() so I get a QAction that I can use for all the menus I must insert before “Help”.

Thanks.

 
  ‹‹ How can I catch Shift + Ctrl key?      Not able to center text veritical using painter. ››

You must log in to post a reply. Not a member yet? Register here!