首页 > 代码库 > Pyqt 以OOP方式动画的效果改变自身窗体大小

Pyqt 以OOP方式动画的效果改变自身窗体大小

 

 代码:

 1 # -*- coding:utf8 -*- 2 from PyQt4.QtGui import * 3 from PyQt4.QtCore import * 4 import sys 5  6 class ani(QWidget): 7     def __init__(self): 8         super(ani, self).__init__() 9         self.OrigHeight = 5010         self.ChangeHeight = 15011         self.setGeometry(QRect(500, 400, 150, self.OrigHeight))  # 在X=500, Y=400 , Length=150 ,   Height=5012         self.btn = QPushButton(u展开, self)13         self.btn.setGeometry(10, 10, 60, 35)14         self.machine = QStateMachine()15         self.connect(self.btn, SIGNAL(clicked()), self.change)16 17     # 动画效果修改窗体大小18     def change(self):19         CurrentHeight = self.height()20         if self.OrigHeight == CurrentHeight:21             startHeight = self.OrigHeight22             endHeight = self.ChangeHeight23             self.btn.setText(u收缩)24         else:25             startHeight = self.ChangeHeight26             endHeight = self.OrigHeight27             self.btn.setText(u展开)28         self.animation = QPropertyAnimation(window, geometry)29         self.animation.setDuration(800)30         self.animation.setStartValue(QRect(500, 400, 150, startHeight))31         self.animation.setEndValue(QRect(500, 400, 150, endHeight))32         self.animation.start()33 34 35 36 if __name__ == __main__:37     app = QApplication(sys.argv)38     window = ani()39     window.show()40     sys.exit(app.exec_())

 效果:

技术分享

 

Pyqt 以OOP方式动画的效果改变自身窗体大小