PyQt:如何动画效果调整对话框大小
下面的代码创建了一个单独的QWidget窗口,并且里面有一个QPushButton按钮,这个按钮连接到resizeDialog()函数。当你按下这个按钮时,窗口的大小会在.resize(200,100)和.resize(600,300)之间切换。
问题是:默认情况下,窗口大小的变化是瞬间完成的。怎么才能用动画来改变这种行为呢?
from PyQt4 import QtCore, QtGui
import sys
class myWindow(QtGui.QWidget):
def __init__(self, parent=None):
super(myWindow, self).__init__(parent)
myLayout = QtGui.QVBoxLayout(self)
Button = QtGui.QPushButton('Resize')
myLayout.addWidget(Button)
Button.setMinimumWidth(200)
Button.clicked.connect(self.resizeDialog)
def resizeDialog(self):
dialog.size().width()==200:
dialog.resize(600,300)
else:
dialog.resize(200,100)
if __name__ == "__main__":
app = QtGui.QApplication(sys.argv)
app.setApplicationName('myApp')
dialog = myWindow()
dialog.resize(200,100)
dialog.show()
sys.exit(app.exec_())
1 个回答
3
def resizeDialog(self):
self.animation = QtCore.QPropertyAnimation(self, "size")
# self.animation.setDuration(1000) #Default 250ms
if self.size().width()==200:
self.animation.setEndValue(QtCore.QSize(600,300))
else:
self.animation.setEndValue(QtCore.QSize(200,100))
self.animation.start()