macos - Qt5 与 MacOS : How to add entries in the application menu?

标签 macos qt5

我正在使用 Qt5 编写应用程序。该应用程序可在 Windows、Linux 上运行,现在可在 MacOS 上运行。

为了确保我的应用程序满足苹果的要求,我想在应用程序菜单中添加条目(首选项、关于...)。

enter image description here

有人知道怎么做吗?

old doc about Qt4.8描述菜单由 Qt 处理,但没有描述要做什么。

最佳答案

我看到了这个问题,正在寻找答案。这些评论很有帮助,但这里有一个更完整的代码示例,应该可以帮助其他人。

ma​​inwindow.h:添加这些包含语句

#include <QMenu>
#include <QAction>

...

private:
    Ui::MainWindow *ui;
    QMenu *mainMenu;
    QAction *aboutAction;

ma​​inwindow.cpp: 初始化函数

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    this->aboutAction = new QAction(0);
    this->aboutAction->setMenuRole(QAction::AboutRole);
    ui->setupUi(this);
    this->mainMenuBar = new QMenuBar(0);
    this->mainMenu = new QMenu(0);
    this->mainMenuBar->addMenu(this->mainMenu);
    this->mainMenu->addAction(this->aboutAction);
    this->setMenuBar(this->mainMenuBar);
}

使用 QT 5.3.2 和 Snow Leopard OS X 10.6.8,QT Creator 3.0.1。

由于您使用的是AboutRole,因此无需指定QAction 的QString 参数。它会自动默认为您想要的。

About Menu for Mac OS X using QT Creator

关于macos - Qt5 与 MacOS : How to add entries in the application menu?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27840858/

相关文章:

c++ - QPushButton 更改布局中小部件的大小

c++ - 如何捕捉键盘布局变化

swift - 使用 Swift 在 NSTextField 中拼写

windows - 需要建议 : simple cross platform (OS-X and Windows) + SQLite development without installation

linux将子文件夹内的文件移动到当前目录

python - 如何更改默认 Python 版本?

macos - 在 OS X 框架中使用 clang_complete

c++ - QXmlStreamReader (Qt5) : get all sub-elements inside a tag

c++ - QTableView选择单个单元格

python - 如何在非 native QFileDialog 中重新填充系统的 "Recent places"?