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

有帮助吗?

解决方案

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);
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top