并行动画组QParallelAnimationGroup

 

动画组QParallelAnimationGroup继承于QAbstractAnimation

 

QParallelAnimationGroup会同时执行添加到该组的所有动画

 

复制代码
 1 import sys
 2 from PyQt5.QtGui import QPixmap
 3 from PyQt5.QtCore import QPropertyAnimation, QParallelAnimationGroup, QRect, QEasingCurve
 4 from PyQt5.QtWidgets import QApplication, QWidget, QLabel
 5 
 6 class Demo(QWidget):
 7     def __init__(self):
 8         super(Demo, self).__init__()
 9         self.resize(600, 600)
10 
11         self.plane = QLabel(self)
12         self.plane.resize(50, 50)
13         self.plane.setPixmap(QPixmap(r'D:\ss\ssss\images\plane.png').scaled(self.plane.size()))
14 
15         self.plane2 = QLabel(self)
16         self.plane2.resize(50, 50)
17         self.plane2.setPixmap(QPixmap('D:\ss\ssss\images\飞机1.png').scaled(self.plane2.size()))
18 
19         self.animation1 = QPropertyAnimation(self.plane, b'geometry')
20         self.animation1.setDuration(2000)
21         self.animation1.setStartValue(QRect(200, 500, 50, 50))
22         self.animation1.setEndValue(QRect(200, 100, 50, 50))
23         self.animation1.setEasingCurve(QEasingCurve.OutCirc)
24         self.animation1.setLoopCount(1)
25 
26         self.animation2 = QPropertyAnimation(self.plane2, b'geometry')
27         self.animation2.setDuration(2000)
28         self.animation2.setStartValue(QRect(300, 500, 50, 50))
29         self.animation2.setEndValue(QRect(300, 100, 50, 50))
30         self.animation2.setEasingCurve(QEasingCurve.OutCirc)
31         self.animation2.setLoopCount(1)
32 
33         self.animation_group = QParallelAnimationGroup(self)  # 实例化一个并行动画
34         self.animation_group.addAnimation(self.animation1)  #添加一个属性动画
35         self.animation_group.addAnimation(self.animation2)
36         self.animation_group.start()   #启动并行动画
37 
38 if __name__ == '__main__':
39     app = QApplication(sys.argv)
40     demo = Demo()
41     demo.show()
42     sys.exit(app.exec_())
复制代码

 

posted @   天子骄龙  阅读(1376)  评论(0编辑  收藏  举报
编辑推荐:
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
阅读排行:
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
点击右上角即可分享
微信分享提示