QMenuBar和QMenu在Mac OS X中不显示 [英] QMenuBar and QMenu doesn't show in Mac OS X

查看:606
本文介绍了QMenuBar和QMenu在Mac OS X中不显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在 Mac OS X 10.7.4 上使用 Qt 4.7.4 ,并且我正在尝试添加QMenuBarQMenu 到我的应用程序,没有成功.

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.

在查找示例时,我发现了基本布局,然后Windows上的界面屏幕快照将显示 File 菜单,这是我要执行的操作:

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:

但是,在Mac OS X上运行此示例不会在应用程序窗口内显示 File 菜单:

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

,它也不会显示在顶部的Mac OS X栏中:

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

这似乎是Mac OS X上的Qt 4.7.4的错误,或者我们需要对源代码进行一些调整才能使其在Mac上运行.

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.

如何解决此问题?

我已经找到了类似的在Stack Overflow上发帖,但没有帮助.

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

推荐答案

代码和Qt中都没有问题.您引用的示例仅在菜单中创建一个Exit操作.在OS X上,此类操作属于应用程序菜单,而不属于文件"菜单.您的应用程序称为qt_menu,这就是应用程序菜单的调用方式,您将在其中找到Quit操作-Qt已正确重命名它以与Apple的HIG一致.在Windows上,习惯将其称为Exit(退出),而在Mac上,这是不好的风格. Qt的行为是正确的,我可以重现.

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.

将其他操作添加到文件菜单,或将一个操作从Exit重命名为其他操作.

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

请注意,Qt不会直接根据动作名称移动动作. Qt根据名称来猜测操作角色.您应该覆盖这些猜测,并使用QAction::setMenuRole()显式设置操作角色.然后,可以在各种平台上正确解释这些角色.

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.

这篇关于QMenuBar和QMenu在Mac OS X中不显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆