QMenuBar and QMenu doesn't show in Mac OS X

谁说我不能喝 提交于 2019-12-06 08:33:17

问题


I'm using Qt 4.7.4 on Mac OS X 10.7.4, and I'm trying to add a QMenuBar and a QMenu to my application without success.

When looking for examples, I found the Basic Layouts and the screenshot of the interface on Windows displays the File menu, which is what I'm trying to do:

However, running this example on Mac OS X doesn't show the File menu inside the application window:

and it also doesn't show in the top Mac OS X bar:

It seems that this is either a bug of Qt 4.7.4 on Mac OS X, or we are required to do some tweaks on the source code to make it work on Mac.

How can I fix this problem?

I've found similar posts on Stack Overflow but none helped.


回答1:


There is no problem in the code, nor in Qt. The example you cite only creates an Exit action in the menu. On OS X, such actions belong in the application menu, not in the File menu. Your application is called qt_menu, and that's how the application menu is called, and that's where you will find the Quit action -- Qt has correctly renamed it to agree with Apple's HIG. On Windows, it'd be customary to call it Exit, on a Mac it's bad style. Qt's behavior is correct, and I can reproduce it.

Add other actions to the file menu, or simply rename the one action from Exit to something else.

Note that Qt doesn't move actions directly based on their name. Qt guesses the action roles based on their name. You should override such guesses and set action roles explicitly using QAction::setMenuRole(). Those roles then get interpreted appropriately on various platforms.



来源:https://stackoverflow.com/questions/11375176/qmenubar-and-qmenu-doesnt-show-in-mac-os-x

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!