当前位置:网站首页>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.

边栏推荐
- CLUE Model Construction Method, Model Validation and Land Use Change Scenario Prediction
- 边境的悍匪—机器学习实战:第四章 训练模型
- 删除当前路径下含某个关键字的所有文件
- JS的值和引用,复制和传递
- [Jiangsu University Self-Chemistry Association stm32F103c8t6] Notes [Introduction to 32 MCUs and Using TIM Output to Compare and Configure PWM]
- [Jiangsu University Automation Association stm32F103c8t6] Notes [Initial 32 MCU and EXTI External Interrupt Initialization Parameter Configuration]
- 逻辑右移和算术右移区别
- 服务器基础知识:包含基本概念,作用,服务器选择,服务器管理等(学习来自米拓建站)
- 你不知道的JS语法篇笔记
- 边境的悍匪—机器学习实战:第九章 无监督学习任务
猜你喜欢

QT serialization 1: readyRead() function, the solution to incomplete data subcontracting

【正点原子】sys.c、sys.h位带操作的简单应用

Antd 树拖拽一些细节,官网没有,摸坑篇

TCP建立连接的过程

jvm之逃逸分析

OpenCV中(rows,cols)与图像(x,y)

Atmospheric particulate matter PMF source analysis

this的指向问题

【江科大自化协stm32F103c8t6】笔记之【入门32单片机及EXTI外部中断初始化参数配置】

Generalized Focal Loss paper reading notes
随机推荐
爬2.12.6的Antd上传图片坑
FPGA解析B码----连载1
CPU缓存一致性问题
ipconfig Command Guide
influxDB运维记录
Duplicate keys detected:‘/da…‘
Sklearn : train_test_split()函数的用法
电子工程师怎么才能规范设计标准、提高设计效率?
【正点原子】IIC的学习与使用(未完...)
【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
点云统计滤波理解
迪文串口屏幕制作(连载一)=====准备工作
QT连载2:基于QT和STM32H750的LORA试验平台(1)
虚拟机栈帧结构
2020-09-03解决pip install安装非常慢[Errno 101] 网络不可达问题
CLUE Model Construction Method, Model Validation and Land Use Change Scenario Prediction
【markdown常用用法】
删除当前路径下含某个关键字的所有文件
【速成MSP430f149】电赛期间学习MSP430f149笔记
探究make_shared效率