官术网_书友最值得收藏!

How to do it…

Let's follow these steps to create a nested animation group to play different animation groups in a sequential order:

  1. We will use the UI from the previous example and add a few more buttons to the main window, like so:
  1. Create all of the animations for the buttons, and then create an easing curve and apply it to all of the animations:
QPropertyAnimation *animation1 = new QPropertyAnimation(ui->pushButton, "geometry");
animation1->setDuration(3000);
animation1->setStartValue(ui->pushButton->geometry());
animation1->setEndValue(QRect(50, 50, 100, 50));

QPropertyAnimation *animation2 = new QPropertyAnimation(ui->pushButton_2, "geometry");
animation2->setDuration(3000);
animation2->setStartValue(ui->pushButton_2->geometry());
animation2->setEndValue(QRect(150, 50, 100, 50));

QPropertyAnimation *animation3 = new QPropertyAnimation(ui->pushButton_3, "geometry");
animation3->setDuration(3000);
animation3->setStartValue(ui->pushButton_3->geometry());
animation3->setEndValue(QRect(250, 50, 100, 50));

Next, apply the following code:

QPropertyAnimation *animation4 = new QPropertyAnimation(ui->pushButton_4, "geometry");
animation4->setDuration(3000);
animation4->setStartValue(ui->pushButton_4->geometry());
animation4->setEndValue(QRect(50, 200, 100, 50));

QPropertyAnimation *animation5 = new QPropertyAnimation(ui->pushButton_5, "geometry");
animation5->setDuration(3000);
animation5->setStartValue(ui->pushButton_5->geometry());
animation5->setEndValue(QRect(150, 200, 100, 50));

QPropertyAnimation *animation6 = new QPropertyAnimation(ui->pushButton_6, "geometry");
animation6->setDuration(3000);
animation6->setStartValue(ui->pushButton_6->geometry());
animation6->setEndValue(QRect(250, 200, 100, 50));

Then, apply the following code:

QEasingCurve curve;
curve.setType(QEasingCurve::OutBounce);
curve.setAmplitude(1.00);
curve.setOvershoot(1.70);
curve.setPeriod(0.30);

animation1->setEasingCurve(curve);
animation2->setEasingCurve(curve);
animation3->setEasingCurve(curve);
animation4->setEasingCurve(curve);
animation5->setEasingCurve(curve);
animation6->setEasingCurve(curve);
  1. Create two animation groups, one for the buttons in the upper column and another one for the lower column:
QParallelAnimationGroup *group1 = new QParallelAnimationGroup;
group1->addAnimation(animation1);
group1->addAnimation(animation2);
group1->addAnimation(animation3);

QParallelAnimationGroup *group2 = new QParallelAnimationGroup;
group2->addAnimation(animation4);
group2->addAnimation(animation5);
group2->addAnimation(animation6);

  1. We will create yet another animation group, which will be used to store the two animation groups we created previously:
QSequentialAnimationGroup *groupAll = new QSequentialAnimationGroup;
groupAll->addAnimation(group1);
groupAll->addAnimation(group2);
groupAll->start();
主站蜘蛛池模板: 建昌县| 北票市| 关岭| 凉城县| 砚山县| 浦北县| 瓮安县| 台安县| 苍山县| 万全县| 新沂市| 蓝山县| 富源县| 盐津县| 胶南市| 新津县| 易门县| 仁寿县| 刚察县| 渭南市| 新龙县| 灵川县| 日照市| 通山县| 开封市| 博爱县| 定远县| 宜宾县| 仙居县| 军事| 梁河县| 大英县| 洞头县| 英超| 永春县| 高阳县| 黔西县| 肥东县| 定结县| 呼伦贝尔市| 吉木萨尔县|