赞
踩
- import PySide6
- from PySide6.QtCore import QRect, QSize, QTimer, QPoint, Qt, QPropertyAnimation
- from PySide6.QtGui import QPixmap, QCursor, QIcon, QMouseEvent, QResizeEvent
- from PySide6.QtWidgets import QApplication, QDialog, QPushButton, QHBoxLayout, QLabel, QSizePolicy, QWidget, \
- QVBoxLayout, QSpacerItem
-
- class ExampleWidget(QWidget):
- def __init__(self, parent=None):
- super(ExampleWidget, self).__init__(parent)
- self.resize(400, 300)
- self.button = QPushButton(self)
- self.button.setGeometry(50, 200, 50, 30)
- self.button.setText("右鍵")
-
- # 动画(必须声明为QWidget的属性)
- self.animation = QPropertyAnimation(self.button, b'geometry')
- # 持续时间
- self.animation.setDuration(1000)
- # 重复次数
- self.animation.setLoopCount(30)
- # 速度曲线(弹性效果)
- self.animation.setEasingCurve(QEasingCurve.InOutElastic)
- # 开始时属性值
- self.animation.setStartValue(QRect(0, 200, 50, 30))
- # 过程
- self.animation.setKeyValueAt(0.2, QRect(50, 200, 50, 30))
- self.animation.setKeyValueAt(0.4, QRect(150, 100, 50, 30))
- self.animation.setKeyValueAt(0.6, QRect(250, 200, 50, 30))
- self.animation.setKeyValueAt(0.8, QRect(350, 200, 50, 30))
- # 结束时属性值
- self.animation.setEndValue(QRect(400, 200, 50, 30))
- # 开始
- self.animation.start()
- # 动画结束后,继续执行其他函数
- self.animation.finished.connect(lambda: print(1))
-
- # 涉及多个属性动画同时执行,可以放到一个组中,然后执行组
- self.group = QParallelAnimationGroup()
- self.group.addAnimation(self.animation)
- # 添加多个
- self.group.start()
-
-
- if __name__ == '__main__':
- app = QApplication([])
- main = ExampleWidget()
- main.show()
- app.exec()
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。