效果预览
说明
可以看到上图中的关于
,设置
,退出
都为Mac系统的样式,这样的样式在Qt并不难实现,只要几条简单在命令就可以完成。
代码
ui->action_About->setMenuRole(QAction::AboutRole); ui->action_Quit->setMenuRole(QAction::QuitRole); ui->action_SetPassword->setMenuRole(QAction::PreferencesRole);
讲解
可以看到上面关键的代码在于QAction::AboutRole
,QAction::QuitRole
,QAction::PreferencesRole
这些命令
其实QAction
它不是只有这么多在选项,具体的可以查看官方链接
Constant | Value | Description |
---|---|---|
QAction::NoRole |
0 | This action should not be put into the application menu |
QAction::TextHeuristicRole |
1 | This action should be put in the application menu based on the action's text as described in the QMenuBar documentation. |
QAction::ApplicationSpecificRole |
2 | his action should be put in the application menu with an application specific role |
QAction::AboutQtRole |
3 | This action matches handles the "About Qt " menu item. |
QAction::AboutRole |
4 | This action should be placed where the "About " menu item is in the application menu. The text of the menu item will be set to "About <application name> ". The application name is fetched from the Info.plist file in the application's bundle (See Qt for Mac OS X - Deployment). |
QAction::PreferencesRole |
5 | This action should be placed where the "Preferences... " menu item is in the application menu. |
QAction::QuitRole |
6 | This action should be placed where the Quit menu item is in the application menu. |
官方链接: http://qt-project.org/doc/qt-5/qaction.html#MenuRole-enum