当前位置:网站首页>QT weekly skills (2)~~~~~~~~~ interface buttons
QT weekly skills (2)~~~~~~~~~ interface buttons
2022-07-30 07:19:00 【transparent light】
前言
思前想后,If made into a weekly tip,It feels a bit stubborn to write for such a long time,Just go to the steps,No need to introduce this or that,The picture above is the picture above,The code is on the code,It also looks good,简单又方便.
第一节:内容
1.Add gallery;
2.添加toolbar;
3.添加action;
4.Transform icon.
第二节:步骤
(1)Add gallery:Right-click on the folder section on the left side of the interface,添加新文件,选择resource,添加图片.具体步骤可以网上搜搜,挺多的.
添加后,You can display your own added pictures,最好是png图片,Other image formats have not been tested,感兴趣的小伙伴可以试试.
(2)添加toolbar,这个很关键,以后uiThe buttons added to the interface are alltoolbar,Specifically why notmainwindow的地方添加,后面会介绍.window on the right,右键,添加toolbar选项.在uiA small bar will appear in the ,这个就是toolbar.
(3)添加action,This is actually the button,Just done nicely,Friends can try it out.There is a page of buttons in the middle,The second is replication,The fourth is to delete,Just look at adding it.name in the text,The object name will appear automaticallyaction+名字.
After adding, click the ellipsis to the right of the icon option below,A picture option will pop up,That is, the image library just added.
添加后,Added below will appearaction.
Double-click the one already added belowaction,The interface just now pops up again,修改文本,Can be modified to Chinese characters,The object name does not change.
Use the mouse to pull the lower oneactionto the strip that just appeared,A vertical bar will automatically appear,松开鼠标,Then add the iconaction就会出现在toolbar中.
运行程序,会出现以下界面:This is the basic framework,然后添加程序.
(4)代码添加:在mainwindow.c里,ui->setupUi(this);下面.
connect(ui->actionred, &QAction::triggered, this,&MainWindow::redout);
connect(ui->actionvol, &QAction::triggered, this,&MainWindow::volout);
connect(ui->actionblue, &QAction::triggered, this,&MainWindow::bluout);
connect(ui->actionorange, &QAction::triggered, this,&MainWindow::oraout);
connect(ui->actionplay, &QAction::triggered, this,&MainWindow::plaout);
解释:前面是action,The name just added,后面是函数.
在mainwindow.hAdd the execution function in ,Similar to declaring a function.
void redout();
void volout();
void bluout();
void oraout();
void plaout();
Then the function body,在mainwindow.c里.
void MainWindow::redout()
{
ui->SHOW->setText("红色");
}
void MainWindow::volout()
{
ui->SHOW->setText("紫色");
}
void MainWindow::bluout()
{
ui->SHOW->setText("蓝色");
}
void MainWindow::oraout()
{
ui->SHOW->setText("橙色");
}
解释:To show which button you clicked,Add a display box,为了好看,怎么添加,直接在uiJust pull it in,起个名字SHOW,最好大写,To differentiate between different things,This is just according to your habit.运行代码.
Click on the purple oneaction后,The displayed purple color will appear,Just execute that code.
为了省空间,And look good,Sometimes a button is made into two pictures,效果如下:
点完之后,Running will become stopped,Just add the following code.
void MainWindow::plaout()
{
beginflag = !beginflag;
if(beginflag == true)
{
ui->actionplay->setIcon(QIcon(":/image/stop.png"));
ui->actionplay->setIconText("停止");
ui->SHOW->setText("运行");
}
else
{
ui->actionplay->setIcon(QIcon(":/image/play.png"));
ui->actionplay->setIconText("运行");
ui->SHOW->setText("停止");
}
}
解释:一个标志位,click to become1,Click to become0.And add different pictures to itaction中,This can only be done in code.It can also be a button with three states,Just add it yourself.
(5)action大小变化:感觉actionButton is too small,Join the following program,Make the icon bigger,and will just setactionThe Chinese characters of are marked below the icon:
ui->toolBar->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
QSize size(35, 35);
ui->toolBar->setIconSize(size);
展示效果如图:
第三节:结语
Join the previous article on how to make a running icon,Add this sectionaction制作,What came out was so interesting,看着也舒服点.
关注的小伙伴直接在历史消息的百度网盘中能找到源码,之前的串口和can传输的源码也在历史消息中,没办法,公众号能不能放大的东西,也不能传输大的东西,所以只能给个百度连接让小伙伴自己下载.需要这个源码的小伙伴可以关注公众号.这个程序的源码随后也将放入公众号中.It may be delayed due to work,Please forgive me, friends.
边栏推荐
- jvm之方法区
- Through the bit operations to convert the characters are case sensitive
- 2021 soft exam intermediate pass
- [Punctuality Atom] Simple application of sys.c, sys.h bit-band operations
- QT每周技巧(1)~~~~~~~~~运行图标
- Difference between logical shift right and arithmetic right shift
- Self-augmented Unpaired Image Dehazing via Density and Depth Decomposition program running record
- 二进制到汇编:进制,原码反码补码,位运算,通用寄存器,内存一套打通
- 高交会重要活动之一|2020中国硬件创新大赛全国总决赛
- QT连载1:readyRead()函数,数据分包不完整解决办法
猜你喜欢
给Vscode配置ESlint语法检查 — ESLint 插件自动格式化设置(实现Ctrl+S 按照ESLint规则自动格式化代码)
动态规划入门 JS
求职准备知识点
二进制到汇编:进制,原码反码补码,位运算,通用寄存器,内存一套打通
Antd 树拖拽一些细节,官网没有,摸坑篇
【速成MSP430f149】电赛期间学习MSP430f149笔记
无法完成包的安装npm ERR! Refusing to install package with name “moment“ under a package also called “moment“
Configure MMdetection environment and train
Target detection, object classification and semantic segmentation of UAV remote sensing images based on PyTorch deep learning
使用Dva项目作Antd的Demo
随机推荐
【Qingdao Station】High-level application of SWAT model and modeling of areas without data, uncertainty analysis and climate change, improvement of land use surface pollution impact model and case analy
OpenCV中(rows,cols)与图像(x,y)
华秋第八届硬创大赛携手NVIDIA初创加速计划,赋能企业发展
Generalized Focal Loss paper reading notes
高交会重要活动之一|2020中国硬件创新大赛全国总决赛
conda常用命令总结(持续更新)
[Jiangsu University of Science and Technology Automation Association stm32F103c8t6] Notes [Initial 32 MCU and TIM timing interrupt initialization parameter configuration]
Antd简单启动一个企业级项目
基于QT的CAN通讯数据实时波形显示(连载八)====“子函数或新类调用ui控件”
【速成MSP430f149】电赛期间学习MSP430f149笔记
高集成度 MCU 市场增大,如何加速 BLDC 领域落地应用
经典排序之插入排序
【江科大自化协stm32F103c8t6】笔记之【入门32单片机及EXTI外部中断初始化参数配置】
昆仑通态屏幕制作(连载1)---接触篇
【江科大自化协stm32F103c8t6】笔记之【入门32单片机及利用TIM输出比较配置PWM】
信号链模拟芯片是什么?
Diwen serial screen production (serialization 1) ===== preparation work
边境的悍匪—机器学习实战:第十章 Keras人工神经网络简介
求职准备知识点
survivor区对象何时进入老年代(深入理解jvm中表述不准确的地方)