zoukankan      html  css  js  c++  java
  • 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 = 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_())

     效果:

  • 相关阅读:
    移动布局---1. 移动端布局基础
    1. CSS新特性之选择器
    1. H5新增语义化标签
    POJ 3281
    poj 1986
    POJ 3728
    poj 2763
    poj 2749
    uva 11294
    LA 3713
  • 原文地址:https://www.cnblogs.com/dcb3688/p/4264183.html
Copyright © 2011-2022 走看看