当前位置:网站首页>QT interface optimization: double click effect
QT interface optimization: double click effect
2022-04-23 14:27:00 【Spiritual health】
Qt Interface optimization : Double click the mouse effect
List of articles
One 、 Double click special effects
Two 、 Use steps
1. .h part
The code is as follows :
#include <QMovie>
#include <QLabel>
#include <QMouseEvent>
#include <QLine>
protected:
void mouseDoubleClickEvent(QMouseEvent *event); // Double click event
2. .cpp part
The code is as follows :
// Double click the mouse effect
void MainWindows::mouseDoubleClickEvent(QMouseEvent *event)
{
// Judge whether it is double clicking with the left mouse button
if(event->button() == Qt::LeftButton)
{
QLabel * label = new QLabel(this);
QMovie * movie = new QMovie("://images/mouse.gif");// load gif picture
// Set up label Automatic adaptation gif Size
label->setScaledContents(true);
label->setMovie(movie);
// Here to call move convenient , Conduct resize, What we need to know is gif The size of is 150*150
label->resize(180,180);
label->setStyleSheet("background-color:rgba(0,0,0,0);");
// Set mouse penetration
label->setAttribute(Qt::WA_TransparentForMouseEvents, true);
// Give Way label The center of the is at the double click position of the current mouse
label->move(event->pos().x()-label->width()/2,event->pos().y()-label->height()/2);
// Start playing gif
movie->start();
label->show();
// binding QMovie The signal of , Judge gif plays
connect(movie, &QMovie::frameChanged, [=](int frameNumber) {
if (frameNumber == movie->frameCount() - 1)//gif The number of plays is 1, Turn off the tag
label->close();
});
}
}
Be careful
gif The background of the moving picture must be transparent !!!
The following is my mouse double click effect picture , You can click the picture , Long press to save and use .
版权声明
本文为[Spiritual health]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204231411423135.html
边栏推荐
- I thought I could lie down and enter Huawei, but I was confused when I received JD / didi / iqiyi offers one after another
- Usage of BC
- JS key value judgment
- On the insecurity of using scanf in VS
- C语言p2选择分支语句详解
- js 进度条,显示加载进度
- Docker (V) MySQL installation
- uni-app消息推送
- 八路抢答器系统51单片机设计【附Proteus仿真、C程序、原理图及PCB文件、元器件清单和论文等】
- Basic regular expression
猜你喜欢
KVM学习资源
直流可调稳压电源的Proteus仿真设计(附仿真+论文等资料)
统信UOS PHP7.2.3升级至PHP7.2.24
Design of single chip microcomputer Proteus for temperature and humidity monitoring and alarm system of SHT11 sensor (with simulation + paper + program, etc.)
Parameter stack pressing problem of C language in structure parameter transmission
Detailed explanation of SAR command
单相交交变频器的Matlab Simulink建模设计,附Matlab仿真、PPT和论文等资料
API Gateway/API 网关(四) - Kong的使用 - 集成Jwt和熔断插件
数组模拟队列进阶版本——环形队列(真正意义上的排队)
Qt实战:云曦日历篇
随机推荐
51 MCU + LCD12864 LCD Tetris game, proteus simulation, ad schematic diagram, code, thesis, etc
如何5分钟上手使用OCR
Quickly understand the three ways of thread implementation
Redis cluster 原理
1 minute to understand the execution process and permanently master the for cycle (with for cycle cases)
初识STL
Notes on Visio drawing topology
Web page, adaptive, proportional scaling
KVM learning resources
分分钟掌握---三目运算符(三元运算符)
Design of single chip microcomputer Proteus for temperature and humidity monitoring and alarm system of SHT11 sensor (with simulation + paper + program, etc.)
c语言在结构体传参时参数压栈问题
在电视屏幕上进行debug调试
The initial C language framework is suitable for review and preliminary understanding
JS recursion (1)
API Gateway/API 网关(四) - Kong的使用 - 集成Jwt和熔断插件
xx项目架构随记
OpenSSH的升级、版本号的修改
流程控制之分支语句
TLS/SSL 协议详解 (28) TLS 1.0、TLS 1.1、TLS 1.2之间的区别