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

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();
主站蜘蛛池模板: 宜良县| 依兰县| 东乡族自治县| 黎川县| 阿鲁科尔沁旗| 海原县| 穆棱市| 易门县| 乾安县| 苍山县| 资阳市| 贡觉县| 广宗县| 武冈市| 延安市| 抚宁县| 庆云县| 芮城县| 伊宁县| 积石山| 大安市| 沙坪坝区| 五家渠市| 稻城县| 博湖县| 赫章县| 潜江市| 南平市| 新巴尔虎右旗| 建瓯市| 东乡| 永仁县| 武鸣县| 五河县| 星座| 郁南县| 武功县| 于都县| 托克托县| 车险| 尖扎县|