当前位置:网站首页>Qt界面优化:鼠标双击特效
Qt界面优化:鼠标双击特效
2022-04-23 14:12:00 【ぃ灵彧が】
Qt界面优化:鼠标双击特效
一、双击特效

二、使用步骤
1. .h部分
代码如下:
#include <QMovie>
#include <QLabel>
#include <QMouseEvent>
#include <QLine>
protected:
void mouseDoubleClickEvent(QMouseEvent *event); //鼠标双击事件
2. .cpp部分
代码如下:
//鼠标双击特效
void MainWindows::mouseDoubleClickEvent(QMouseEvent *event)
{
//判断是否为鼠标左键双击
if(event->button() == Qt::LeftButton)
{
QLabel * label = new QLabel(this);
QMovie * movie = new QMovie("://images/mouse.gif");//加载gif图片
//设置label自动适应gif的大小
label->setScaledContents(true);
label->setMovie(movie);
//这里为了调用move方便,进行resize,需要知道的是gif的大小本来也就是150*150
label->resize(180,180);
label->setStyleSheet("background-color:rgba(0,0,0,0);");
//设置鼠标穿透
label->setAttribute(Qt::WA_TransparentForMouseEvents, true);
//让label的中心在当前鼠标双击位置
label->move(event->pos().x()-label->width()/2,event->pos().y()-label->height()/2);
//开始播放gif
movie->start();
label->show();
//绑定QMovie的信号,判断gif播放次数
connect(movie, &QMovie::frameChanged, [=](int frameNumber) {
if (frameNumber == movie->frameCount() - 1)//gif播放次数为1,关闭标签
label->close();
});
}
}
注意点
gif动图的背景必须是透明的!!!
以下为我的鼠标双击特效图片,大家可以点击该图片,长按进行保存使用。

版权声明
本文为[ぃ灵彧が]所创,转载请带上原文链接,感谢
https://blog.csdn.net/m0_54754302/article/details/124342491
边栏推荐
猜你喜欢
随机推荐
爬虫练习题(一)
dp-能量项链
操作系统常见面试题目:
ThreadGroup ThreadGroup implémente l'interface threadfactory en utilisant la classe Introduction + Custom thread Factory
顺序栈的基本操作
获取线程返回值Future接口与FutureTask类使用介绍
Pass in external parameters to the main function in clion
xx项目架构随记
ansible及常用模块的使用
How to do a project easily
Operation instructions of star boundary automatic text translator (advanced version)
Nacos作为配置中心(四) 使用Demo
Introduction to loan market quotation interest rate (LPR) and loan benchmark interest rate
MySQL数据库讲解(十)
mysql 5.1升级到5.69
剑指offer刷题(1)--面向华为
flannel 原理 之 TUN模式
Operation instructions of star boundary text automatic translator
redis数据库讲解二(redis高可用、持久化、性能管理)
Uni app message push








