栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

PyQt5中QPropertyAnimation属性的应用

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

PyQt5中QPropertyAnimation属性的应用

import sys
from PyQt5 import QtCore
from PyQt5.QtCore import QPropertyAnimation, QRect
from PyQt5.QtWidgets import QWidget, QApplication, QPushButton


class AnimWindow(QWidget):
    def __init__(self, parent=None):
        super(AnimWindow, self).__init__(parent)
        self.btn = QPushButton('Exit', self)
        self.animation = None
        self.animation2 = None
        self.draw_ui()

    def draw_ui(self):
        self.setGeometry(0, 0, 1024, 600)
        self.btn.setGeometry(50, 50, 100, 50)
        self.btn.clicked.connect(self.close)

    def closeEvent(self, event):
        if self.animation is None and self.animation2 is None:
            self.animation = QPropertyAnimation(self, b'geometry')
            self.animation2 = QPropertyAnimation(self, b'windowOpacity')
            self.animation.setStartValue(QRect(0, 0, self.width(), self.height()))
            self.animation.setEndValue(QRect(1024, 600, 0, 0))
            self.animation2.setStartValue(1)
            self.animation2.setEndValue(0)
            self.animation.finished.connect(self.close)
            self.animation2.finished.connect(self.close)
            self.animation.setDuration(1500)
            self.animation.start()
            self.animation2.setDuration(1500)
            self.animation2.start()
            event.ignore()


if __name__ == '__main__':
    app = QApplication(sys.argv)
    window = AnimWindow()
    window.setWindowFlags(QtCore.Qt.FramelessWindowHint)
    window.show()
    sys.exit(app.exec_())

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/971707.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号