PyQt5 (一百零四) 用动画效果改变窗口的尺寸 案例

 

PyQt5 用动画效果改变窗口的尺寸 案例

QPropertyAnimation

 

import sys

from PyQt5.QtCore import Qt, QRect, QPropertyAnimation
from PyQt5.QtGui import QIcon
from PyQt5.QtWidgets import QHBoxLayout, QPushButton, QMessageBox, QApplication, QVBoxLayout, QWidget, \
    QLabel, QGridLayout, QLineEdit, QTextEdit, QFormLayout, QComboBox, QMainWindow

from CommonHelper import CommonHelper
'''
PyQt5 用动画效果改变窗口的尺寸 案例

QPropertyAnimation

'''


class AnimWindowDemo(QWidget):

    def __init__(self):
        super().__init__()
        self.initUI()

    def initUI(self):
        self.OrigHeight = 50;
        self.ChangeHeight = 150;
        # 设置定位和左上角坐标
        self.setGeometry(QRect(500,400,150,self.OrigHeight))
        # 设置窗口标题
        self.setWindowTitle('动画效果改变窗口大小尺寸 的演示')
        # 设置窗口图标
        # self.setWindowIcon(QIcon('../web.ico'))

        # self.resize(477,258)

        self.btn = QPushButton('展开',self)
        self.btn.setToolTip('提示文本')
        self.btn.setGeometry(10,10,60,35)
        self.btn.clicked.connect(self.change)


        vbox = QVBoxLayout()
        vbox.addWidget(self.btn)
        self.setLayout(vbox)


    def change(self):
        currentHeight = self.height()
        if self.OrigHeight == currentHeight:
            startHeight = self.OrigHeight
            endHeight = self.ChangeHeight
            self.btn.setText('收缩')
        else:
            startHeight = self.ChangeHeight
            endHeight = self.OrigHeight
            self.btn.setText('展开')

        self.animation = QPropertyAnimation(self,b'geometry')
        self.animation.setDuration(500)
        self.animation.setStartValue(QRect(500,400,150,startHeight))
        self.animation.setEndValue(QRect(500,400,150,endHeight))
        self.animation.start()

    def mousePressEvent(self,event):
        # 左击
        if event.button() == Qt.LeftButton:

            print(event.globalPos())
            print(event.pos())
            print(self.pos())

        # 右击
        if event.button() == Qt.RightButton:
            self.close()


if __name__ == '__main__':
    app = QApplication(sys.argv)
    # 设置应用图标
    app.setWindowIcon(QIcon('../web.ico'))
    w = AnimWindowDemo()

    # 0-1,1表示不透明,0表示完全透明
    # w.setWindowOpacity(0.7)

    w.show()
    sys.exit(app.exec_())

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值