简述
QParallelAnimationGroup类提供动画的并行组。
QParallelAnimationGroup - 一个动画容器,当它启动的时候它里面的所有动画也启动,即:并行运行所有动画,当持续时间最长的动画完成时动画组也随之完成。
详细描述
QParallelAnimationGroup可以被当做任何其它的QAbstractAnimation动画,例如:暂停、重置、添加到其它动画组中。
1 QParallelAnimationGroup *group = new QParallelAnimationGroup;
2 group->addAnimation(anim1);
3 group->addAnimation(anim2);
4 group->start();
这个例子中,anim1、anim2是QPropertyAnimation。
示例
下面,我们通过QParallelAnimationGroup 来构建一个并行动画组,并添加属性动画QPropertyAnimation,这里也可以使用addAnimation()添加其它动画/动画组,就不予演示了。
效果
源码
1 MainWindow::MainWindow(QWidget *parent)
2 : CustomWindow(parent)
3 {
4 ...
5
6 QPushButton *pStartButton = new QPushButton(this);
7 pStartButton->setText(QString::fromLocal8Bit("开始动画"));
8
9 QList<QLabel *> list;
10 QStringList strList;
11 strList << QString::fromLocal8Bit("一去丶二三里") << QString::fromLocal8Bit("青春不老,奋斗不止");
12
13 for (int i = 0; i < strList.count(); ++i)
14 {
15 QLabel *pLabel = new QLabel(this);
16 pLabel->setText(strList.at(i));
17 pLabel->setAlignment(Qt::AlignCenter);
18 pLabel->setStyleSheet("color: rgb(0, 160, 230);");
19 list.append(pLabel);
20 }
21
22 // 动画一
23 QPropertyAnimation *pAnimation1 = new QPropertyAnimation(list.at(0), "geometry");
24 pAnimation1->setDuration(1000);
25 pAnimation1->setStartValue(QRect(0, 0, 100, 30));
26 pAnimation1->setEndValue(QRect(120, 130, 100, 30));
27 pAnimation1->setEasingCurve(QEasingCurve::OutBounce);
28
29 // 动画二
30 QPropertyAnimation *pAnimation2 = new QPropertyAnimation(list.at(1), "geometry");
31 pAnimation2->setDuration(1000);
32 pAnimation2->setStartValue(QRect(120, 130, 120, 30));
33 pAnimation2->setEndValue(QRect(170, 0, 120, 30));
34 pAnimation2->setEasingCurve(QEasingCurve::OutInCirc);
35
36 m_pGroup = new QParallelAnimationGroup(this);
37
38 // 添加动画
39 m_pGroup->addAnimation(pAnimation1);
40 m_pGroup->addAnimation(pAnimation2);
41
42 // 循环2次
43 m_pGroup->setLoopCount(2);
44
45 connect(pStartButton, SIGNAL(clicked(bool)), this, SLOT(startAnimation()));
46
47 ...
48 }
49
50 // 开始动画
51 void MainWindow::startAnimation()
52 {
53 m_pGroup->start();
54 }
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 一个奇形怪状的面试题:Bean中的CHM要不要加volatile?
· [.NET]调用本地 Deepseek 模型
· 一个费力不讨好的项目,让我损失了近一半的绩效!
· 全网最简单!3分钟用满血DeepSeek R1开发一款AI智能客服,零代码轻松接入微信、公众号、小程
· .NET 10 首个预览版发布,跨平台开发与性能全面提升
· 《HelloGitHub》第 107 期
· 全程使用 AI 从 0 到 1 写了个小工具
· 从文本到图像:SSE 如何助力 AI 内容实时呈现?(Typescript篇)
2020-06-24 Qt 保持GUI响应的几种方法
2020-06-24 Qt QApplication::processEvents();//不停地处理事件,让程序保持响应
2020-06-24 Qt 窗体固定大小,避免拉伸
2020-06-24 Qt QCoreApplication:processEvents()可能会引起递归,导致栈溢出崩溃
2020-06-24 Qt 隐藏最大化和最小化按钮