当前位置:   article > 正文

Qt第三十九章:属性动画_self.animation = qpropertyanimation(self.ui.frame_

self.animation = qpropertyanimation(self.ui.frame_scope_cursors_main, b"mini
  1. import PySide6
  2. from PySide6.QtCore import QRect, QSize, QTimer, QPoint, Qt, QPropertyAnimation
  3. from PySide6.QtGui import QPixmap, QCursor, QIcon, QMouseEvent, QResizeEvent
  4. from PySide6.QtWidgets import QApplication, QDialog, QPushButton, QHBoxLayout, QLabel, QSizePolicy, QWidget, \
  5. QVBoxLayout, QSpacerItem
  6. class ExampleWidget(QWidget):
  7. def __init__(self, parent=None):
  8. super(ExampleWidget, self).__init__(parent)
  9. self.resize(400, 300)
  10. self.button = QPushButton(self)
  11. self.button.setGeometry(50, 200, 50, 30)
  12. self.button.setText("右鍵")
  13. # 动画(必须声明为QWidget的属性)
  14. self.animation = QPropertyAnimation(self.button, b'geometry')
  15. # 持续时间
  16. self.animation.setDuration(1000)
  17. # 重复次数
  18. self.animation.setLoopCount(30)
  19. # 速度曲线(弹性效果)
  20. self.animation.setEasingCurve(QEasingCurve.InOutElastic)
  21. # 开始时属性值
  22. self.animation.setStartValue(QRect(0, 200, 50, 30))
  23. # 过程
  24. self.animation.setKeyValueAt(0.2, QRect(50, 200, 50, 30))
  25. self.animation.setKeyValueAt(0.4, QRect(150, 100, 50, 30))
  26. self.animation.setKeyValueAt(0.6, QRect(250, 200, 50, 30))
  27. self.animation.setKeyValueAt(0.8, QRect(350, 200, 50, 30))
  28. # 结束时属性值
  29. self.animation.setEndValue(QRect(400, 200, 50, 30))
  30. # 开始
  31. self.animation.start()
  32. # 动画结束后,继续执行其他函数
  33. self.animation.finished.connect(lambda: print(1))
  34. # 涉及多个属性动画同时执行,可以放到一个组中,然后执行组
  35. self.group = QParallelAnimationGroup()
  36. self.group.addAnimation(self.animation)
  37. # 添加多个
  38. self.group.start()
  39. if __name__ == '__main__':
  40. app = QApplication([])
  41. main = ExampleWidget()
  42. main.show()
  43. app.exec()

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/盐析白兔/article/detail/81363
推荐阅读
  

闽ICP备14008679号