Qt之菜单栏工具栏入门
菜单栏基本操作
创建菜单栏
QMenuBar *menuBar = new QMenuBar(this); //1.创建菜单栏
menuBar->setGeometry(,,width(),); //设置大小 QMenu *fileMenu = new QMenu("File",this); //2.创建菜单
//3.创建行为(Action)
QAction *fileCreateAction = new QAction("create",this);
QAction *fileSaveAction = new QAction("save",this);
QAction *fileImportAction = new QAction("import",this);
QAction *fileExportAction = new QAction("export",this);
//4.将行为添加到菜单
fileMenu->addAction(fileSaveAction);
fileMenu->addAction(fileImportAction);
fileMenu->addAction(fileExportAction);
fileMenu->addAction(fileCreateAction);
//5.将菜单添加到菜单栏
menuBar->addMenu(fileMenu);
可以通过自定义槽函数实现想要的功能
//行为连接到具体的槽函数
connect(fileCreateAction,SIGNAL(triggered()),this,SLOT(createFile())); //槽函数需要实现
connect(fileSaveAction,SIGNAL(triggered()),this,SLOT(saveFile()));
connect(fileImportAction,SIGNAL(triggered()),this,SLOT(importFile()));
connect(fileExportAction,SIGNAL(triggered()),this,SLOT(exportFile()));
为菜单再添加菜单实现多级菜单
QMenu *optionMenu = new QMenu("Option",this); //创建菜单
QAction *optionSystemAction = new QAction("System",this);
QMenu *ComparisionMenu = new QMenu("Comparison",this);//**这里创建再一个菜单
QAction *optionFindEdgeAction = new QAction("Find edge",this);
QAction *optionSetDecimalAction = new QAction("Set decima",this);
optionMenu->addAction(optionSystemAction);
//添加二级菜单
optionMenu->addMenu(ComparisionMenu);//***
QAction *openAction = new QAction("open",this);
QAction *closeAction = new QAction("close",this);
//为二级菜单添加行为
ComparisionMenu->addAction(openAction);
ComparisionMenu->addAction(closeAction);
optionMenu->addAction(optionFindEdgeAction);
optionMenu->addAction(optionSetDecimalAction);
menuBar->addMenu(optionMenu);
工具栏
//新建一个工具栏
QToolBar *toolBar = new QToolBar("toolbar",this);
//设置大小
toolBar->setGeometry(,,width(),); //新建行为(Action)
tAction1 = new QAction(QIcon(":/icon/icon/Vegetables-_11.png"),"Vegetables",this);
tAction2 = new QAction(QIcon(":/icon/icon/Vegetables-_12.png"),"Vegetables",this);
tAction3 = new QAction(QIcon(":/icon/icon/Vegetables-_13.png"),"Vegetables",this); //设置可选中,默认为false,triggered(bool)信号传递的bool永远为false
tAction1->setCheckable(true);
tAction2->setCheckable(true);
tAction3->setCheckable(true); //可以通过判断是否选中设置不同的样式
connect(tAction1,SIGNAL(triggered(bool)),this,SLOT(changeIcon(bool))); //添加行为
toolBar->addAction(tAction1);
toolBar->addAction(tAction2);
toolBar->addAction(tAction3);
void MainWindow::changeIcon(bool boolValue)
{
if(boolValue)
tAction1->setIcon(QIcon(":/icon/icon/Vegetables-_1.png"));
else
tAction1->setIcon(QIcon(":/icon/icon/Vegetables-_11.png"));
}
Qt之菜单栏工具栏入门的更多相关文章
- 《Qt Quick 4小时入门》学习笔记2
http://edu.csdn.net/course/detail/1042/14805?auto_start=1 Qt Quick 4小时入门 第五章:Qt Quick基本界面元素介绍 1. ...
- 《Qt Quick 4小时入门》学习笔记4
http://edu.csdn.net/course/detail/1042/14806?auto_start=1 Qt Quick 4小时入门 第七章:处理鼠标与键盘事件 1.处理鼠标事件 鼠标信号 ...
- 《Qt Quick 4小时入门》学习笔记3
http://edu.csdn.net/course/detail/1042/14807?auto_start=1 Qt Quick 4小时入门 第八章:Qt Quick中的锚(anchors)布局 ...
- 《Qt Quick 4小时入门》学习笔记
http://edu.csdn.net/course/detail/1042/14804?auto_start=1 Qt Quick 4小时入门 第五章:Qt Quick里的信号与槽 QML中 ...
- Robot Framework--02 菜单栏&工具栏
转自:http://blog.csdn.net/tulituqi/article/details/7584795 我把RIDE的界面大致分了四个区域:菜单栏.工具栏.案例及资源区.工作区,如下图 菜单 ...
- Qt 从菜单栏打开文件
Qt从菜单栏的下拉菜单选择文件 构造函数中设置打开动作信息 //打开文件 m_menu = ui.menu; // m_menu->menuAction = new QAction(QIcon( ...
- gvim设置字体和隐藏菜单栏工具栏
liunx下面设置字体 set guifont=Monaco\ 注意空格的位置,其他写法不认哦! Windows下面设置 set guifont=Monaco:h 隐藏菜单栏 set guioptio ...
- qt之菜单栏的创建
很久之前学习的Qt菜单栏的消息响应,昨天发现忘记了,今天又拿起来了,记一下笔记: 就像平常我们常用的软件一样,每个程序基本都有菜单栏,在菜单栏中有很多功能性的按钮,点击这些按钮会弹出有对应的菜单功能, ...
- PyQt4 菜单栏 + 工具栏 + 状态栏 + 中心部件 生成一个文本编辑部件示例
我们将创建一个菜单栏.一个工具栏.一个状态栏和一个中心部件. #!/usr/bin/python # -*- coding:utf-8 -*- import sys from PyQt4 import ...
随机推荐
- ES6 —— 数组总结
1. map:映射 一个对一个 arr.map(function(item) { ... }) 可以配合箭头函数:arr.map(item => ... ) let arr1 = [1 ...
- Java实现inputstream流的复制
获取到一个inputstream后,可能要多次利用它进行read的操作.由于流读过一次就不能再读了,而InputStream对象本身不能复制,而且它也没有实现Cloneable接口,所以得想点办法. ...
- Day8 linux软件包管理
软件包的两种形式 qq.tar.gz (需要编译 源码翻译成二进制)/ rpm (直接安装) rpm的文件名分为5部分 name名称 version版本编号 release发布次数 ...
- #20175120彭宇辰-实验一《Java开发环境的熟悉》实验报告
Java开发环境的熟悉-1 实验要求:1 .建立“自己学号exp1”的目录2 .在“自己学号exp1”目录下建立src,bin等目录3 .javac,java的执行在“自己学号exp1”目录4 .提交 ...
- Java基于opencv—透视变换矫正图像
很多时候我们拍摄的照片都会产生一点畸变的,就像下面的这张图 虽然不是很明显,但还是有一点畸变的,而我们要做的就是把它变成下面的这张图 效果看起来并不是很好,主要是四个顶点找的不准确,会有一些偏差,而且 ...
- uva 202
#include <iostream> #include<cstdio> #include<cstring> #include<algorithm> # ...
- JavaScript杂谈(第六天)
js中可以使用Function创建函数 var func=new Function(); 这个对象可以将字符串转换为函数 var func=new Function("console.wri ...
- 学习笔记CB007:分词、命名实体识别、词性标注、句法分析树
中文分词把文本切分成词语,还可以反过来,把该拼一起的词再拼到一起,找到命名实体. 概率图模型条件随机场适用观测值条件下决定随机变量有有限个取值情况.给定观察序列X,某个特定标记序列Y概率,指数函数 e ...
- 我的linux部署nginx步骤记录
http://www.runoob.com/linux/nginx-install-setup.html 安装prce找不到GCC c++文件 解决方法: yum install gcc-c++^C ...
- java设计模式概述
java的设计模式大体上分为三大类: 创建型模式(5种):工厂方法模式,抽象工厂模式,单例模式,建造者模式,原型模式. 结构型模式(7种):适配器模式,装饰器模式,代理模式,外观模式,桥接模式,组合模 ...