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(),改变属性,实现动画;

套路二中的设置关键帧里面的参数就是setGeometry()中使用到的参数QRect;

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();//开始动画;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

qincjun

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值