当前位置:网站首页>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
边栏推荐
- 获取线程返回值Future接口与FutureTask类使用介绍
- 顺序表的操作,你真的学会了吗?
- redis数据库讲解(三)redis数据类型
- Thread group ThreadGroup uses introduction + custom thread factory class to implement threadfactory interface
- ansible及常用模块的使用
- Wechat applet rotation map swiper
- Introduction to the use of semaphore for inter thread control
- How to do a project easily
- 修改Firebase Emulators的默认侦听IP
- Notes on Visio drawing topology
猜你喜欢
A table splitting implementation scheme of MySQL and InnoDB, MyISAM and MRG_ Introduction to MyISAM and other engine application scenarios
About the configuration and use of json5 in nodejs
Pass in external parameters to the main function in clion
x509证书cer格式转pem格式
KVM学习资源
API Gateway/API 网关(二) - Kong的使用 - 负载均衡Loadbalance
TUN 设备原理
krpano全景之vtour文件夹和tour
MySQL数据库讲解(九)
Operation instructions of star boundary automatic text translator (advanced version)
随机推荐
Flop effect
JS progress bar, displaying the loading progress
如何轻松做好一个项目
Returns the subscript after array sorting
解决ssh配置文件优化以及连接慢的问题
Get the thread return value. Introduction to the use of future interface and futuretask class
setcontext getcontext makecontext swapcontext
How does void * exist?
使用Executors类快速创建线程池
时间复杂度计算举例
source insight via samba
mysql 5.1升级到5.69
flannel 原理 之 TUN模式
mysql查询库大小
顺序表的操作,你真的学会了吗?
贷款市场报价利率(LPR)与贷款基准利率介绍
Processing MKDIR: unable to create directory 'AAA': read only file system
redis数据库讲解(四)主从复制、哨兵、Cluster群集
微信小程序将原生请求通过es6的promise来进行优化
After entering the new company, the operation and maintenance engineer can understand the deployment of the system from the following items