문제

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