串行动画组QSequentialAnimationGroup

该类就是用来按照动画添加顺序来执行动画的。我们只用实例化该类,然后通过调用addAnimation()或者insertAnimation()方法把各个动画添加进去就可以了

 1 import sys
 2 from PyQt5.QtGui import QPixmap
 3 from PyQt5.QtCore import QPropertyAnimation, QSequentialAnimationGroup, QRect
 4 from PyQt5.QtWidgets import QApplication, QWidget, QLabel
 5 
 6 
 7 class Demo(QWidget):
 8     def __init__(self):
 9         super(Demo, self).__init__()
10         self.resize(600, 600)
11 
12         self.plane = QLabel(self)
13         self.plane.resize(50, 50)
14         self.plane.setPixmap(QPixmap(r'D:\ss\ssss\images\plane.png').scaled(self.plane.size()))
15 
16         self.animation1 = QPropertyAnimation(self.plane, b'geometry')  #创建一个属性动画对象
17         #动画目标标签  位置和大小
18         self.animation1.setDuration(2000)
19         self.animation1.setStartValue(QRect(300, 500, 50, 50))
20         self.animation1.setEndValue(QRect(200, 400, 50, 50))
21         self.animation1.setLoopCount(1)
22 
23         self.animation2 = QPropertyAnimation(self.plane, b'geometry')
24         self.animation2.setDuration(2000)
25         self.animation2.setStartValue(QRect(200, 400, 50, 50))
26         self.animation2.setEndValue(QRect(400, 300, 50, 50))
27         self.animation2.setLoopCount(1)
28 
29         self.animation3 = QPropertyAnimation(self.plane, b'geometry')
30         self.animation3.setDuration(2000)
31         self.animation3.setStartValue(QRect(400, 300, 50, 50))
32         self.animation3.setEndValue(QRect(200, 200, 50, 50))
33         self.animation3.setLoopCount(1)
34 
35         self.animation_group = QSequentialAnimationGroup(self) #实例化一个串行动画
36         self.animation_group.addAnimation(self.animation1)  #添加属性动画
37         self.animation_group.addPause(1000)           #设置动画暂停时间
38         self.animation_group.addAnimation(self.animation2)
39         self.animation_group.addAnimation(self.animation3)
40         self.animation_group.start()   #启动串行动画
41 
42 
43 if __name__ == '__main__':
44     app = QApplication(sys.argv)
45     demo = Demo()
46     demo.show()
47     sys.exit(app.exec_())

猜你喜欢

转载自www.cnblogs.com/liming19680104/p/10426342.html