当前位置:网站首页>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
边栏推荐
猜你喜欢

Tongxin UOS php7 2.3 upgrade to php7.0 two point two four

LM317的直流可调稳压电源Multisim仿真设计(附仿真+论文+参考资料)

Proteus simulation design of DC adjustable regulated power supply (with simulation + paper and other data)

Uni app message push

On the insecurity of using scanf in VS

常见存储类型和FTP主被动模式解析

流程控制之分支语句

Branch statement of process control

API Gateway/API 网关(四) - Kong的使用 - 集成Jwt和熔断插件

ArrayList集合基本使用
随机推荐
API gateway / API gateway (IV) - use of Kong - Integrated JWT and fuse plug-in
source insight via samba
Proteus simulation design of DC adjustable regulated power supply (with simulation + paper and other data)
Introduction to the use of countdownlatch and cyclicbarrier for inter thread control
逻辑卷创建与扩容
ssh限制登录的四种手段
C语言p2选择分支语句详解
一篇博客让你学会在vscode上编写markdown
redis的五种数据类型
C语言知识点精细详解——数据类型和变量【2】——整型变量与常量【1】
555定时器+74系列芯片搭建八路抢答器,30s倒计时,附Proteus仿真等
在电视屏幕上进行debug调试
Matrix exchange row and column
Golang 对分片 append 是否会共享数据
Branch statement of process control
TLS/SSL 协议详解 (28) TLS 1.0、TLS 1.1、TLS 1.2之间的区别
gif转为静态图片处理
flannel 原理 之 子网划分
C语言知识点精细详解——初识C语言【1】——你不能不知的VS2022调试技巧及代码实操【2】
On the insecurity of using scanf in VS