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

How to do it…

Let's create an animation group by following these steps:

  1. We will use the previous example but, this time, we will add two more push buttons to the main window, as shown in the following screenshot:
  1. Define the animation for each of the push buttons in the main window's constructor:
QPropertyAnimation *animation1 = new QPropertyAnimation(ui->pushButton, "geometry");
animation1->setDuration(3000);
animation1->setStartValue(ui->pushButton->geometry());
animation1->setEndValue(QRect(50, 200, 100, 50));

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

QPropertyAnimation *animation3 = new QPropertyAnimation(ui->pushButton_3, "geometry");
animation3->setDuration(3000);
animation3->setStartValue(ui->pushButton_3->geometry());
animation3->setEndValue(QRect(250, 200, 100, 50));
  1. Create an easing curve and apply the same curve to all three animations:
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);
  1. Once you have applied the easing curve to all three animations, we will then create an animation group and add all three animations to the group:
QParallelAnimationGroup *group = new QParallelAnimationGroup;
group->addAnimation(animation1);
group->addAnimation(animation2);
group->addAnimation(animation3);
  1. Call the start() function from the animation group we just created:
group->start();
主站蜘蛛池模板: 广南县| 治县。| 嘉禾县| 南川市| 包头市| 华坪县| 沅江市| 芷江| 伊川县| 邮箱| 绥中县| 南漳县| 布拖县| 镇巴县| 尼玛县| 富蕴县| 江油市| 东乡县| 平乐县| 星座| 蒙城县| 长沙县| 罗江县| 遵义县| 阳谷县| 新郑市| 福建省| 衡阳市| 磐石市| 鞍山市| 建瓯市| 綦江县| 和龙市| 赤水市| 集贤县| 中牟县| 深州市| 沾益县| 上思县| 镇雄县| 饶平县|