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

来源:互联网 发布:正则表达式 手机号js码 编辑:程序博客网 时间:2024/06/05 20:17

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

    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),因此您可以将其添加到另一个组。通过这种方式,您可以构建一个动画的树形结构,该动画指定动画何时相互影响。

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