QPropertyAnimation不适用于子窗口小部件 [英] QPropertyAnimation doesn't work with a child widget
本文介绍了QPropertyAnimation不适用于子窗口小部件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
以下代码未按预期为按钮设置动画。但是,如果该按钮是独立按钮,则可以使用,当它是子窗口小部件时,它将停止工作。我在这里做错了什么?
The below code doesn't animate the button as expected. But it works if the button is stand alone and stops working when it is a child widget. What am I doing wrong here?
我正在Ubuntu上尝试此操作。
I'm trying this on Ubuntu.
class TestWindow(QtGui.QWidget):
def __init__(self):
QtGui.QWidget.__init__(self)
self.button = QtGui.QPushButton("Ok")
self.button.setParent(self)
self.button.setGeometry(QtCore.QRect(0,0,50,50))
self.button.clicked.connect(self.anim)
def anim(self):
animation = QtCore.QPropertyAnimation(self.button, "geometry")
animation.setDuration(10000)
animation.setStartValue(QtCore.QRect(0,0,0,0))
animation.setEndValue(QtCore.QRect(0,0,200,200))
animation.start()
if __name__ == '__main__':
app = QtGui.QApplication(sys.argv)
r = TestWindow()
r.show()
sys.exit(app.exec_())
推荐答案
我刚刚在Ubu上尝试过使用PySide的ntu 10.04。尝试保留对动画对象的引用,它在此处解决了问题:
I've just tried it on Ubuntu 10.04 with PySide. Try to keep a reference to your animation object, it solved the problem here:
def anim(self):
animation = QtCore.QPropertyAnimation(self.button, "geometry")
animation.setDuration(10000)
animation.setStartValue(QtCore.QRect(0,0,0,0))
animation.setEndValue(QtCore.QRect(0,0,200,200))
animation.start()
self.animation = animation
这篇关于QPropertyAnimation不适用于子窗口小部件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文