Qt仿音乐播放器:动画类

一、基本属性

复制代码
#include<QPropertyAnimation>//头文件

property:性质属性

animation:动画、动画效果、动漫

QPropertyAnimation:可以对对任何QObject的子类的属性进行动画的展示;只要存在set方法

QPropertyAnimation(QObject *target, const QByteArray &propertyName, QObject *parent = nullptr)

参数:

QObject *target:此参数表示要被操作对象的地址

const QByteArray &propertyName:请大家看一下上方红色的文字;此参数里面所写的内容是对target对象本身带有的属性;比如:传入的是geometry;target本身有geometry属性;同时还具有setGeometry()函数;这样就可以在动画类内部自动进行setGeometry(),改变属性,实现动画;

QObject *parent = nullptr:此参数表示父亲对象的地址;并挂起对象树

套路一:

复制代码
QPropertyAnimation* line1Animal=new QPropertyAnimation(ui->line1,"geometry",this);
    
line1Animal->setDuration(2000);// 动画运行效果持续多少毫秒
line1Animal->setKeyValueAt(0,QRect(0,15,3,0)); //设置第0帧
line1Animal->setKeyValueAt(0.5,QRect(0,0,3,15));//设置第0.5帧
line1Animal->setKeyValueAt(1,QRect(0,15,3,0));//设置最后一帧
line1Animal->setLoopCount(-1);//若为-1,动画一直运行、若大于0,则重复多少次后停止;
line1Animal->start();//开始运行动画;

套路二:

复制代码
QPropertyAnimation *animation = new QPropertyAnimation(myWidget, "geometry");
animation->setDuration(10000);
animation->setStartValue(QRect(0, 0, 100, 30));//开始帧
animation->setEndValue(QRect(250, 250, 100, 30));//结束帧
animation->start();//开始动画;
相关推荐
datalover20 小时前
CompletableFuture 使用示例
java·开发语言
m0_6860416120 小时前
C++中的适配器模式变体
开发语言·c++·算法
清风~徐~来20 小时前
【视频点播系统】WebSocketpp 介绍及使用
开发语言
爱吃大芒果20 小时前
Flutter for OpenHarmony 实战:mango_shop 路由系统的配置与页面跳转逻辑
开发语言·javascript·flutter
学***542320 小时前
如何轻松避免网络负载过大
开发语言·网络·php
RANCE_atttackkk20 小时前
Springboot+langchain4j的RAG检索增强生成
java·开发语言·spring boot·后端·spring·ai·ai编程
梵刹古音20 小时前
【C语言】 格式控制符与输入输出函数
c语言·开发语言·嵌入式
Acrelhuang21 小时前
工商业用电成本高?安科瑞液冷储能一体机一站式解供能难题-安科瑞黄安南
大数据·开发语言·人工智能·物联网·安全
hello 早上好21 小时前
03_JVM(Java Virtual Machine)的生命周期
java·开发语言·jvm
沐雪架构师21 小时前
LangChain 1.0 Agent开发实战指南
开发语言·javascript·langchain