質問

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