View Full Version : Select first QMenu from QMenuBar using ALT key

24th May 2014, 16:25
Hello everyone!

I'm having the folowing problem: I want the first QMenu from QMenuBar to be selected when I press the ALT key.
I saw that if I create a new project and I create some QMenu objects and add them to the QMenuBar I get the desired behavior, but I'm working on a big project and I can't get this to work. Did anybody had this problem, has an idea what might be causing this?

I've tried to change the NativeMenuBar property but that didn't help.

Thank you!

24th May 2014, 19:19
As the QMenuBar documentation says:

The ampersand in the menu item's text sets Alt+F as a shortcut for this menu.

fileMenu = menuBar()->addMenu(tr("&File"));

The first menu is selected when you press ALT because Qt doesn't know what the second key ("F") is going to be until you press it. It doesn't actually do anything except highlight it.

If the menus in your existing app are not defined with the "&" shortcuts, then the ALT key has nothing to select and you don't get this behavior. So you'll need to go back and edit either the UI files or the C++ code to insert the "&" where you want them.