Question

How to open Qt4 main menu from code? I want F10 key to behave same way, as if File menu was clicked by mouse

Was it helpful?

Solution

In the slot which you connect to shortcut in some way (QAction, QShortcut, etc.), do the following:

menuBar->setActiveAction(fileMenu->menuAction());

Note, however, that it may not always work as you expect. On some platforms (at least on Mac OS), native menu bar is being used by default, and your file menu won't pop up in the right place. You could disable the use of native menu bar, but then your app will (obviously) not look native anymore (on those systems):

menuBar->setNativeMenuBar(false);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top