qmenu 不适用于 MAC (Qt Creator)
我在 Mac 10.6 上,尝试使用 Qt (Creator) 创建菜单,但菜单没有出现。我从其他 PC 用户那里得到了一些反馈,相同的代码似乎可以在 Windows 上运行:
#include <QtGui>
#include "MyClass.h"
MyClass::MyClass()
{
// Create a menu
//QMainWindow::setMenuBar(new QMenuBar());
QMenu* my_menu = new QMenu("&File", this);
menuBar()->addMenu(my_menu);
}
您听说过 Mac 上的此类问题吗?
工具栏工作正常,但菜单不行。
编辑 : 新代码:
#include <QtGui>
#include "MMenu.h"
MMenu::MMenu()
{
QMenu* fileMenu = new QMenu("&File", this);
QMenuBar *menuBar = new QMenuBar(0);
menuBar->addMenu(fileMenu);
//menuBar()->addMenu(fileMenu);
}
谢谢
i'm on Mac 10.6, i'm trying to create a menu with Qt (Creator), but the menu does not appear. I had some feed back from other pc users, and the same code seems to work on windows :
#include <QtGui>
#include "MyClass.h"
MyClass::MyClass()
{
// Create a menu
//QMainWindow::setMenuBar(new QMenuBar());
QMenu* my_menu = new QMenu("&File", this);
menuBar()->addMenu(my_menu);
}
Have you heard about this kind of problem with mac?
The toolbar works fine, but the menu doesn't.
EDIT :
new code :
#include <QtGui>
#include "MMenu.h"
MMenu::MMenu()
{
QMenu* fileMenu = new QMenu("&File", this);
QMenuBar *menuBar = new QMenuBar(0);
menuBar->addMenu(fileMenu);
//menuBar()->addMenu(fileMenu);
}
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
首先,您可能对 addMenu(QString) 函数感兴趣,该函数一步返回创建的 QMenu。
其次,尝试在菜单中添加一些内容。 Mac 可能正在优化空菜单。但我知道这应该可行,我已经编写了一个在 OSX 上运行良好的程序,以这种方式初始化菜单。
Firstly, you may be interested in the addMenu(QString) function, which returns the created QMenu in one step.
Second, try adding something to the menu. Macs may be optimizing the empty menu away. But I know this should work, I've written a program that did just fine on OSX that initialized the menus in this way.
在构造函数中或任何您想要的地方。如果您只想在主窗口运行之前看一下它,那就这样做
in the constructor or wherever you want it. And if you just wanna have a look at it before your main windows runs, just do