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 ...
随机推荐
- ES5数组、对象常用方法总结
数组方法: Array.isArray(items);判断判断一个变量是否包含数组数据: forEach(function(value, index, fullArray){ }); every(fu ...
- mayavi与X11的一些坑总结
1. Mayavi:https://docs.enthought.com/mayavi/mayavi/ 适合渲染各种和图形有关的数据.在大批量处理数据时,一般不希望对每一个渲染好的对象都将其显示出来, ...
- tableview前端基础设计(初级版)
tableView前端基础设计 实现的最终效果 操作目的:熟悉纯代码编辑TableView和常用的相关控件SearchBar.NavigationBar.TabBar等,以及布局和基本功能的实现. 一 ...
- 使用 requests
基本实例 #利用requests库发送get请求 import requests r = requests.get('http://httpbin.org/get') print(r.text) 利用 ...
- Spring @EventListener 异步中使用condition的问题
@EventListener是spring在4.2+推出的更好的使用spring事件架构的方式,并且异步方式也很好设定 但是在spring4.2.7版本上使用eventlistener的conditi ...
- 软件安装配置笔记(三)——ArcGIS系列产品安装与配置(补档)(附数据库连接及数据导入)
在前两篇安装配置笔记之后,就忘记把其他安装配置笔记迁移过来了,真是失误失误!趁现在其他文档需要赶紧补上. 目录: 一.ArcMap 二.ArcMap连接数据库并导入数据 三.Arcgis Pro 四. ...
- Python练习一
#给一个字符串,统计其中的数字.字母和其他类型字符的个数r=raw_input("请输入一个字符串:")num=0str=0oth=0for i in r: if (i.isdig ...
- Spring事务<tx:annotation-driven/>的理解(Controller使用@Transactional)
在使用Spring的时候,配置文件中我们经常看到 annotation-driven 这样的注解,其含义就是支持注解,一般根据前缀 tx.mvc 等也能很直白的理解出来分别的作用. <tx:an ...
- C语言-第2次作业得分
作业链接:https://edu.cnblogs.com/campus/hljkj/CS20180的2/homework/2292 作业链接:https://edu.cnblogs.com/campu ...
- Python学习笔记,day5
Python学习笔记,day5 一.time & datetime模块 import本质为将要导入的模块,先解释一遍 #_*_coding:utf-8_*_ __author__ = 'Ale ...