C++ GUI Qt4编程(07)-3.1menu
1. C++ GUI Qt4编程第三章,添加menu菜单。
2. mainwindow.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H #include <QMainWindow> class QMenu;
class QAction; class MainWindow : public QMainWindow
{
Q_OBJECT public:
MainWindow(); private:
/*菜单*/
QMenu *fileMenu;
QMenu *editMenu;
QMenu *toolsMenu;
QMenu *optionsMenu;
QMenu *helpMenu; /*File动作*/
QAction *newAction;
QAction *openAction;
QAction *saveAction;
QAction *saveAsAction;
QAction *exitAction; /*Edit动作*/
QAction *cutAction;
QAction *copyAction;
QAction *pasteAction;
QAction *deleteAction;
QMenu *selectSubMenu;
QAction *selectRowAction;
QAction *selectColumnAction;
QAction *selectAllAction;
QAction *findAction;
QAction *goToCellAction; /*Tools动作*/
QAction *recalculateAction;
QAction *sortAction; /*Options动作*/
QAction *showGridAction;
QAction *autoRecalculateAction; /*Help动作*/
QAction *aboutAction;
QAction *aboutQtAction; void createMenus();
void createActions();
void createFileActions();
void createEditActions();
void createToolsActions();
void createOptionsActions();
void createHelpAction();
}; #endif /*MAINWINDOW_H*/
3. mainwindow.cpp
#include <QMenu>
#include <QMenuBar>
#include <QAction>
#include "mainwindow.h" MainWindow::MainWindow()
{
createActions();
createMenus();
} void MainWindow::createMenus()
{
/*file menu*/
fileMenu = menuBar()->addMenu(tr("&File"));
fileMenu->addAction(newAction);
fileMenu->addAction(openAction);
fileMenu->addAction(saveAction);
fileMenu->addAction(saveAsAction);
fileMenu->addSeparator();
fileMenu->addAction(exitAction); /*edit menu*/
editMenu = menuBar()->addMenu(tr("&Edit"));
editMenu->addAction(cutAction);
editMenu->addAction(copyAction);
editMenu->addAction(pasteAction);
editMenu->addAction(deleteAction);
selectSubMenu = editMenu->addMenu(tr("&Select"));
selectSubMenu->addAction(selectRowAction);
selectSubMenu->addAction(selectColumnAction);
selectSubMenu->addAction(selectAllAction);
editMenu->addSeparator();
editMenu->addAction(findAction);
editMenu->addAction(goToCellAction); /*tools menu*/
toolsMenu = menuBar()->addMenu(tr("&Tools"));
toolsMenu->addAction(recalculateAction);
toolsMenu->addAction(sortAction); /*option menu*/
optionsMenu = menuBar()->addMenu(tr("&Option"));
optionsMenu->addAction(showGridAction);
optionsMenu->addAction(autoRecalculateAction); /*间隔器*/
menuBar()->addSeparator(); /*help menu*/
helpMenu = menuBar()->addMenu(tr("&Help"));
helpMenu->addAction(aboutAction);
helpMenu->addAction(aboutQtAction);
} void MainWindow::createActions()
{
createFileActions();
createEditActions();
createToolsActions();
createOptionsActions();
createHelpAction();
} /*file动作*/
void MainWindow::createFileActions()
{
newAction = new QAction(tr("&New"), this);
openAction = new QAction(tr("&Open"), this);
saveAction = new QAction(tr("&Save"), this);
saveAsAction = new QAction(tr("Save &As..."), this);
exitAction = new QAction(tr("E&xit"), this);
} /*edit动作*/
void MainWindow::createEditActions()
{
cutAction = new QAction(tr("Cu&t"), this);
copyAction = new QAction(tr("&Copy"), this);
pasteAction = new QAction(tr("&Paste"), this);
deleteAction = new QAction(tr("&Delete"), this);
selectRowAction = new QAction(tr("&Row"), this);
selectColumnAction = new QAction(tr("&Column"), this);
selectAllAction = new QAction(tr("&All"), this);
findAction = new QAction(tr("&Find..."), this);
goToCellAction = new QAction(tr("&Go to Cell..."), this);
} /*tools动作*/
void MainWindow::createToolsActions()
{
recalculateAction = new QAction(tr("&Recalculate"), this);
sortAction = new QAction(tr("&Sort..."), this);
} /*options动作*/
void MainWindow::createOptionsActions()
{
showGridAction = new QAction(tr("&Show Grid"), this);
autoRecalculateAction = new QAction(tr("Auto-Recalculate"), this);
} /*help动作*/
void MainWindow::createHelpAction()
{
aboutAction = new QAction(tr("&About"), this);
aboutQtAction = new QAction(tr("About &Qt"), this);
}
4. main.cpp
#include <QApplication>
#include "mainwindow.h" int main(int argc, char *argv[])
{
QApplication app(argc, argv); MainWindow *win = new MainWindow;
win->show(); return app.exec();
}


C++ GUI Qt4编程(07)-3.1menu的更多相关文章
- C++ GUI Qt4编程(10)-3.4spreadsheet
1. C++ GUI Qt4编程第三章,增加spreadsheet. 2. spreadsheet.h /**/ #ifndef SPREADSHEET_H #define SPREADSHEET_H ...
- C++ GUI Qt4编程(09)-3.3spreadsheet-toolbar
1. C++ GUI Qt4编程第三章,增加工具栏.状态栏和快捷键. 2. mainwindow.h /**/ #ifndef MAINWINDOW_H #define MAINWINDOW_H #i ...
- C++ GUI Qt4编程(08)-3.2spreadsheet-resource
1. C++ GUI Qt4编程第三章,图片使用资源机制法. 2. 步骤: 2-1. 在resource文件夹下,新建images文件,存放图片. 2-2. 新建spreadsheet.qrc文件,并 ...
- C++ GUI Qt4编程(03)-1.3layout
1. 根据C++ GUI Qt4编程(第二版)整理2. 系统:centos7: Qt版本:5.5.13. 程序:layout.cpp #include <QApplication> #i ...
- C++ GUI Qt4编程(02)-1.2quit
1. 根据C++ GUI Qt4编程(第二版)整理2. 系统:centos7: Qt版本:5.5.13. 程序:quit.cpp #include <QApplication> #inc ...
- C++ GUI Qt4编程(01)-1.1Hello Qt
1. 根据C++ GUI Qt4编程(第二版)整理2. 系统:centos7: Qt版本:5.5.13. 程序:hello.cpp #include <QApplication> #in ...
- C++ GUI Qt4编程-创建自定义窗口部件
C++ GUI Qt4编程-创建自定义窗口部件 Qtqt4 通过Qt窗口部件进行子类化或者直接对QWidget进行子类化,就可以创建自定义窗口部件,下面示范两种方式,并且也会说明如何把自定义窗口部 ...
- C++ GUI Qt4 编程 (第二版)
[加拿大]JasminBlanchette [英]MarkSummerfield . 电子工业 2008. 前几天的问题多是因为版本不兼容的问题. QT本身Q4 Q5就有版本问题,然后集成到VS08 ...
- C++ GUI Qt4编程(13)-6.2preferencedialog
1. 主要介绍了QStackedLayout.QListWidget.QDialogButtonBox的简单用法.2. QStackedLayout: 要使某个特定的子窗口部件可见,可以用setC ...
随机推荐
- 利用AdaBoost方法构建多个弱分类器进行分类
1.AdaBoost 思想 补充:这里的若分类器之间有比较强的依赖关系;对于若依赖关系的分类器一般使用Bagging的方法 弱分类器是指分类效果要比随机猜测效果略好的分类器,我们可以通过构建多个弱分类 ...
- Django框架 之 MTV模型、 基本命令、简单配置
浏览目录 MTV模型 Django框架前奏 Django基础必备三件套 Djaogo基本命令 MTV模型 Django的MTV分别代表: Model(模型):负责业务对象与数据库的对象(ORM) Te ...
- 6.Dump域内用户Hash姿势集合
本文转自先知社区,原文链接:https://xz.aliyun.com/t/2527#toc-10 原文地址:https://pentestlab.blog/2018/07/04/dumping-do ...
- JavaScript 组件编写
说明 这是一个联系人名过滤组件,还提供可选的"大小写是否敏感"选项,默认大小写不敏感. 一.HTML 结构 <ul class="contacts"> ...
- delphi窗体启动外部exe
uses Winapi.Windows; WinExec(PAnsiChar(Application.ExeName), sw_normal); // PAnsiChar : string to ...
- 类的 where T : class 泛型类型约束
where T : struct | T必须是一个结构类型where T : class T必须是一个类(class)类型where T : new() | T必须要有一个无参构造函数where T ...
- CentOS7-扩容挂载磁盘
1.1查看新磁盘,可以看到/dev/sdb是新的未挂载的磁盘: [root@localhost ~]# fdisk -l 1.2硬盘分区 ,进入fdisk模式 进入fdisk模式 [root@loca ...
- Sublime Text 2插件推荐
必装Package Control 使用Ctrl+`快捷键或者通过View->Show Console菜单打开命令行,粘贴如下代码: import urllib2,os; pf='Package ...
- mvc 高并发解决方案之一---存储过程
MVC用户访问多线程,一般的lock是无法造成单例的. 存储过程既是一种解决方案,先来看看存储过程优缺点: A. 存储过程允许标准组件式编程 存储过程创建后可以在程序中被多次调用执行,而不必重新编写该 ...
- kali linux之漏洞扫描
发现弱点:基于端口服务扫描结果版本信息,搜索已公开的漏洞数据库 使用弱点扫描器实现漏洞管理 弱点扫描类型(扫描结果不能确定是不是准确的,应该综合对待威胁) 主动扫描:有身份验证,无身份验证 被动扫描: ...