Qt动画框架-(3)分组动画

这一节简单介绍分组动画
准备工作

    Widget w;
    TransparentWidget t; //透明窗体
    QLabel pix;
    QPushButton btn("一个按钮");

    pix.setPixmap(QPixmap("E:/pic/poi2.jpg"));
    pix.setParent(&w);
    w.addItem(&pix);
    w.show();

    btn.setParent(&t);
    t.addItem(&btn);
    t.show();

其中透明窗体可以参考,我的另一篇文章:Qt透明窗体
http://blog.csdn.net/gx864102252/article/details/72779801

这里写图片描述
图1 显示图片和按钮

  • 分组动画
    QPropertyAnimation animation1(&w, "geometry");
    QPropertyAnimation animation2(&t, "geometry");

    QParallelAnimationGroup group;
    group.addAnimation(&animation1);
    group.addAnimation(&animation2);

    QDesktopWidget desktop;
    animation1.setDuration(2000);
    animation1.setStartValue(QRect(desktop.width() / 2,
                            desktop.height() / 2,
                            pix.width(),
                            pix.height()));
    animation1.setEndValue(QRect(desktop.width() / 2,
                          0,
                          pix.width(),
                          pix.height()));

    animation2.setDuration(4000);
    animation2.setStartValue(QRect(desktop.width() / 2,
                            desktop.height() / 2,
                            pix.width(),
                            pix.height()));
    animation2.setEndValue(QRect(desktop.width() / 2,
                          0,
                          pix.width(),
                          pix.height()));


    animation2.setEasingCurve(QEasingCurve::OutBounce);
    group.start();

依旧是从屏幕中心运动到最上方,按钮运动4s,图片运动2s,按钮设置了曲线动画
这里写图片描述
图2 分组动画
分组中的每个动画都是独立的

  • 顺序动画

QSequentialAnimationGroup将按顺序播放动画。它在上一个完成后,在列表中开始下一个动画。

这里写图片描述
图3 顺序动画
由于动画组是动画本身(组合模式 Composite Pattern),因此您可以将其添加到另一个组。通过这种方式,您可以构建一个动画的树形结构,该动画指定动画何时相互影响。

有关状态机的动画相关后期继续更新

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值