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

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();
主站蜘蛛池模板: 神池县| 中西区| 玛沁县| 昌平区| 泰宁县| 和平县| 巫山县| 南澳县| 于都县| 东宁县| 桃园市| 昂仁县| 横峰县| 东丰县| 富源县| 宝兴县| 罗甸县| 万安县| 环江| 禄丰县| 塔城市| 宜黄县| 临潭县| 海宁市| 建水县| 鲜城| 威远县| 塘沽区| 汶上县| 东台市| 江北区| 肇州县| 炉霍县| 凤翔县| 牡丹江市| 博爱县| 靖西县| 萨嘎县| 韶关市| 逊克县| 临城县|