qmenu 不适用于 MAC (Qt Creator)

发布于 2024-12-15 11:20:12 字数 690 浏览 4 评论 0原文

我在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

不可一世的女人 2024-12-22 11:20:12

首先,您可能对 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.

慕烟庭风 2024-12-22 11:20:12
QMenu *fileMenu = QMainWindow::menuBar()->addMenu(tr("&File"));
fileMenu->addAction(your_action);
fileMenu->addAction(your_second_action); 
...

在构造函数中或任何您想要的地方。如果您只想在主窗口运行之前看一下它,那就这样做

fileMenu->exec();
QMenu *fileMenu = QMainWindow::menuBar()->addMenu(tr("&File"));
fileMenu->addAction(your_action);
fileMenu->addAction(your_second_action); 
...

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

fileMenu->exec();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文