【Qt动画框架】

虽然现在大多数项目的动画都是用QML在做了,反正了解了解也没什么坏处,或许以后也用得到。

一 Qt动画框架

缺少一张图。。。公司网速太慢,传不上去。
(其实也就是Qt动画框架类,了解即可)

Qt动画框架类

QAbstractAnimation 所有动画类的基类

QAnimationGroup 动画容器类的抽象基类 (记忆一下,挺重要)
——QParallelAnimationGroup 并行动画容器 (多个动画同时运行)
——QSequentialAnimationGroup 串行动画容器 (动画一个接一个的运行)

QEasingCurve 动画控制的缓和曲线类(动画的运行方式(参考手机界面弹出方式))

QPauseAnimation 对象暂停延时

QPropertyAnimation Qt动画属性操作(重要,用于同QObject的属性通信(比如widget的一些大小和坐标))

QTimeLine 动画控制的时间片类
QVariantAnimation 动画类的抽象基类

Qt动画的例子

这里就不多说废话了,直接上例子,看看里面的一些方法和机制
(也都是网上常有的一些例子)

1.窗口的移动

**这里就看看这几个方法的使用
.setDuration
.setStartValue
.setEndValue**

//创建一个按钮
   QPushButton button("Animated Button");
   button.show();

//创建一个动画的属性对象(该动画,基于button)
   QPropertyAnimation animation(&button, "geometry");
   //关于这个构造函数,我已开始有很多问题
   //第一个参数,哪个控件
   //第二个参数,是该控件的某个属性(动画也就是基于该属性的变化)
   animation.setDuration(10000);
           //设置动画的持续时间————动画从开始到结束的时间
   animation.setStartValue(QRect(0, 0, 150, 50));
           //设置起始位置
   animation.setEndValue(QRect(250, 250, 100, 30));
           //设置结束位置
   animation.start();

2.窗口的移动—升级1

**主要看看这个方法的使用
.setKeyValueAt**

QPushButton button("Animated Button");
button.show();

QPropertyAnimation animation(&button, "geometry");
animation.setDuration(10000);
            //动画设置10s
animation.setKeyValueAt(0, QRect(0, 0, 100, 30));
animation.setKeyValueAt(0.8, QRect(250, 250, 100, 30));
animation.setKeyValueAt(1, QRect(0, 0, 100, 30));
            //前8s 向右下移动
            //后2s 向左上移动
animation.start();

3.窗口的移动—升级2

**主要关注这些方法的使用
.setEasingCurve**

QPushButton button("Animated Button");
button.show();

QPropertyAnimation animation(&button, "geometry");
animation.setDuration(3000);

animation.setStartValue(QRect(0, 0, 100, 30));
animation.setEndValue(QRect(250, 250, 100, 30));

animation.setEasingCurve(QEasingCurve::OutBounce);
        //控制移动的轨迹(回弹)
animation.start();

4.窗口的移动—升级3

多个动画窗口,这里就要注意
QSequentialAnimationGroup
QParallelAnimationGroup
这两个类的使用

并行动画

QPushButton *bonnie = new QPushButton("Bonnie");
bonnie->show();

QPushButton *clyde = new QPushButton("Clyde");
clyde->show();

QPropertyAnimation *anim1 = new QPropertyAnimation(bonnie, "geometry");
    // 这里的动画是基于bonnie的
QPropertyAnimation *anim2 = new QPropertyAnimation(clyde, "geometry");
    //这里的动画是基于clyde的

QParallelAnimationGroup *group = new QParallelAnimationGroup;
    //这里注意啦:这就是并行输出,同时的
group->addAnimation(anim1);
group->addAnimation(anim2);
group->start();

串行动画

QPushButton button("Animated Button");
button.show();

QPropertyAnimation anim1(&button, "geometry");
anim1.setDuration(3000);
anim1.setStartValue(QRect(0, 0, 100, 30));
anim1.setEndValue(QRect(500, 500, 100, 30));
QPropertyAnimation anim2(&button, "geometry");

anim2.setDuration(3000);
anim2.setStartValue(QRect(500, 500, 100, 30));
anim2.setEndValue(QRect(1000, 500, 100, 30));

QSequentialAnimationGroup group;
        //这里就是串行啦
group.addAnimation(&anim1);
group.addAnimation(&anim2);
group.start();

这里遗留一个问题,就是状态机 和 动画的协作。。。下章写。。。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值