串行动画组QSequentialAnimationGroup
QSequentialAnimationGroup继承于QAbstractAnimation
按顺序执行动画
该类就是用来按照动画添加顺序来执行动画的。我们只用实例化该类,然后通过调用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_())
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 基于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)