PyQt: 练习 动画 QAbstractAnimationPyQt: 练习 动画 QAbstractAnimationPyQt: 练习 动画 QAbstractAnimationPyQt: 练习 动画 QAbstractAnimation
  • 首页
  • 博客
  • 书签
  • 文件
  • 分析
  • 登录

PyQt: 练习 动画 QAbstractAnimation

发表 admin at 2022年4月28日
类别
  • Practice
标签
import sys
from PyQt5.Qt import *


class Window(QWidget):
    def __init__(self):
        super().__init__()
        self.setup_ui()

    def setup_ui(self):
        self.setWindowTitle("Qt桌面应用程序")
        self.resize(600, 600)

        self.push_button_1 = QPushButton("暂停", self)
        self.push_button_1.setStyleSheet("background-color:red")
        self.push_button_1.resize(100, 100)
        self.push_button_1.move(150, 150)

        self.push_button_2 = QPushButton("继续", self)
        self.push_button_2.resize(100, 100)
        self.push_button_2.setStyleSheet("background-color:green")

        self.label_1 = QLabel(self)
        self.label_1.move(200, 0)
        self.label_2 = QLabel(self)
        self.label_2.move(200, 15)

        self.set_animation()

        self.push_button_1.clicked.connect(self.animation_group.pause)
        self.push_button_2.clicked.connect(self.animation_group.resume)

    def set_animation(self):
        self.animation_group = QParallelAnimationGroup(self)

        self.animation_push_button_1 = QPropertyAnimation(self.push_button_1, b"pos", self)
        self.animation_push_button_1.setKeyValueAt(0, QPoint(150, 150))
        self.animation_push_button_1.setKeyValueAt(0.25, QPoint(350, 150))
        self.animation_push_button_1.setKeyValueAt(0.5, QPoint(350, 350))
        self.animation_push_button_1.setKeyValueAt(0.75, QPoint(150, 350))
        self.animation_push_button_1.setKeyValueAt(1, QPoint(150, 150))
        self.animation_push_button_1.setDuration(5000)

        self.animation_push_button_2 = QPropertyAnimation(self.push_button_2, b"pos", self)
        self.animation_push_button_2.setKeyValueAt(0, QPoint(0, 0))
        self.animation_push_button_2.setKeyValueAt(0.25, QPoint(0, 500))
        self.animation_push_button_2.setKeyValueAt(0.5, QPoint(500, 500))
        self.animation_push_button_2.setKeyValueAt(0.75, QPoint(500, 0))
        self.animation_push_button_2.setKeyValueAt(1, QPoint(0, 0))
        self.animation_push_button_2.setDuration(5000)
        self.animation_push_button_2.setEasingCurve(QEasingCurve.InBounce)
        # self.animation_push_button_2.setDirection(QAbstractAnimation.Backward)

        self.animation_group.addAnimation(self.animation_push_button_1)
        self.animation_group.addAnimation(self.animation_push_button_2)
        self.animation_group.setLoopCount(3)

        self.animation_group.currentLoopChanged.connect(lambda value: self.label_1.setText(
            f"循环:{self.animation_group.currentLoop() + 1} / 共{self.animation_group.loopCount()}次"))
        self.animation_group.stateChanged.connect(
            lambda value1, value2: self.label_2.setText(f"状态:新{value1} 旧{value2}"))

        self.animation_group.start()
        self.label_1.setText(f"循环:{self.animation_group.currentLoop() + 1} / 共{self.animation_group.loopCount()}次")


if __name__ == '__main__':
    app = QApplication(sys.argv)
window = Window()
window.show()
sys.exit(app.exec_())

发表回复 取消回复

您的电子邮箱地址不会被公开。 必填项已用*标注

类别

  • Cat
  • Python
  • MySQL
  • Django
  • Html/CSS
  • JavaScript
  • Vue
  • RegExp
  • php
  • Practice
  • Virtualization
  • Linux
  • Windows
  • Android
  • NAS
  • Software
  • Hardware
  • Network
  • Router
  • Office
  • WordPress
  • SEO
  • English
  • Games
  • Recipes
  • living
  • Memorandum
  • Essays
  • 未分类

归档

©2015-2023 艾丽卡 Blog support@alaica.com
      ajax-loader