並行動畫組QParallelAnimationGroup

 

動畫組QParallelAnimationGroup繼承於QAbstractAnimationapp

 

QParallelAnimationGroup會同時執行添加到該組的全部動畫oop

 

 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_())
相關文章
相關標籤/搜索