- Qt5 C++ GUI Programming Cookbook
- Lee Zhi Eng
- 224字
- 2021-07-02 12:18:01
How to do it…
Let's follow these steps to create a nested animation group to play different animation groups in a sequential order:
- We will use the UI from the previous example and add a few more buttons to the main window, like so:

- 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);
- 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);
- 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();
推薦閱讀
- 郎景和院士“關(guān)愛(ài)女性健康”系列:婦科腫瘤的故事
- MR臨床手冊(cè)
- 陳衛(wèi)川中回醫(yī)臨證實(shí)錄方
- 寬體探測(cè)器CT臨床應(yīng)用
- 健康快車的故事
- 眼科手術(shù)器械清洗消毒滅菌技術(shù)操作規(guī)程
- 超聲醫(yī)學(xué)專科能力建設(shè)專用初級(jí)教材:介入分冊(cè)
- 預(yù)防老年人跌倒健康教育教程(老年人用書)
- 斜視臨床診療
- 兒童音樂(lè)治療理論與應(yīng)用方法
- 胎兒磁共振影像診斷學(xué)
- 預(yù)防老年人跌倒健康教育教程(工作人員用書)
- 悅讀中醫(yī):首屆全國(guó)悅讀中醫(yī)校園之星作品集(第二輯)
- 呼吸與危重癥醫(yī)學(xué)2014-2015
- 你好,我是阿斯伯格員工