码迷,mamicode.com
首页 > Windows程序 > 详细

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

时间:2015-01-31 16:11:22      阅读:325      评论:0      收藏:0      [点我收藏+]

标签:

 

 代码:

 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 = 50
10         self.ChangeHeight = 150
11         self.setGeometry(QRect(500, 400, 150, self.OrigHeight))  # 在X=500, Y=400 , Length=150 ,   Height=50
12         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.OrigHeight
22             endHeight = self.ChangeHeight
23             self.btn.setText(u收缩)
24         else:
25             startHeight = self.ChangeHeight
26             endHeight = self.OrigHeight
27             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方式动画的效果改变自身窗体大小

标签:

原文地址:http://www.cnblogs.com/dcb3688/p/4264183.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!