zoukankan      html  css  js  c++  java
  • Qt QParallelAnimationGroup 并行动画组

    简述

    QParallelAnimationGroup类提供动画的并行组。

    QParallelAnimationGroup - 一个动画容器,当它启动的时候它里面的所有动画也启动,即:并行运行所有动画,当持续时间最长的动画完成时动画组也随之完成。

    详细描述

    QParallelAnimationGroup可以被当做任何其它的QAbstractAnimation动画,例如:暂停、重置、添加到其它动画组中。

    1 QParallelAnimationGroup *group = new QParallelAnimationGroup;
    2 group->addAnimation(anim1);
    3 group->addAnimation(anim2);
    4 group->start();

    这个例子中,anim1、anim2是QPropertyAnimation。

    示例

    下面,我们通过QParallelAnimationGroup 来构建一个并行动画组,并添加属性动画QPropertyAnimation,这里也可以使用addAnimation()添加其它动画/动画组,就不予演示了。

    效果

    源码

     1 MainWindow::MainWindow(QWidget *parent)
     2     : CustomWindow(parent)
     3 {
     4     ...
     5 
     6     QPushButton *pStartButton = new QPushButton(this);
     7     pStartButton->setText(QString::fromLocal8Bit("开始动画"));
     8 
     9     QList<QLabel *> list;
    10     QStringList strList;
    11     strList << QString::fromLocal8Bit("一去丶二三里") << QString::fromLocal8Bit("青春不老,奋斗不止");
    12 
    13     for (int i = 0; i < strList.count(); ++i)
    14     {
    15         QLabel *pLabel = new QLabel(this);
    16         pLabel->setText(strList.at(i));
    17         pLabel->setAlignment(Qt::AlignCenter);
    18         pLabel->setStyleSheet("color: rgb(0, 160, 230);");
    19         list.append(pLabel);
    20     }
    21 
    22     // 动画一
    23     QPropertyAnimation *pAnimation1 = new QPropertyAnimation(list.at(0), "geometry");
    24     pAnimation1->setDuration(1000);
    25     pAnimation1->setStartValue(QRect(0, 0, 100, 30));
    26     pAnimation1->setEndValue(QRect(120, 130, 100, 30));
    27     pAnimation1->setEasingCurve(QEasingCurve::OutBounce);
    28 
    29     // 动画二
    30     QPropertyAnimation *pAnimation2 = new QPropertyAnimation(list.at(1), "geometry");
    31     pAnimation2->setDuration(1000);
    32     pAnimation2->setStartValue(QRect(120, 130, 120, 30));
    33     pAnimation2->setEndValue(QRect(170, 0, 120, 30));
    34     pAnimation2->setEasingCurve(QEasingCurve::OutInCirc);
    35 
    36     m_pGroup = new QParallelAnimationGroup(this);
    37 
    38     // 添加动画
    39     m_pGroup->addAnimation(pAnimation1);
    40     m_pGroup->addAnimation(pAnimation2);
    41 
    42     // 循环2次
    43     m_pGroup->setLoopCount(2);
    44 
    45     connect(pStartButton, SIGNAL(clicked(bool)), this, SLOT(startAnimation()));
    46 
    47     ...
    48 }
    49 
    50 // 开始动画
    51 void MainWindow::startAnimation()
    52 {
    53     m_pGroup->start();
    54 }
  • 相关阅读:
    C++逐行读取文本文件的正确做法
    <Android Framework 之路>Android5.1 Camera Framework(一)
    zeromq-4.1.2在windows下的编译
    Duilib应用修改程序图标方法
    gdal集成kml库的做法
    使用DWR实现JS调用服务端Java代码
    DirectUI界面编程(六)实现右键弹出菜单
    如何设计系统的错误码及错误信息
    TCP协议格式
    UDP协议
  • 原文地址:https://www.cnblogs.com/ybqjymy/p/14926517.html
Copyright © 2011-2022 走看看