QPropertyAnimation不适用于子窗口小部件

Ano*_*oop 3 python animation qt pyqt

下面的代码没有按预期为按钮设置动画.但是如果按钮是独立的,它可以工作,当它是子窗口小部件时停止工作.我在这做错了什么?

我在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_())
Run Code Online (Sandbox Code Playgroud)

fvi*_*tor 5

我刚刚在使用PySide的Ubuntu 10.04上尝试过它.尝试保持对动画对象的引用,它解决了这里的问题:

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
Run Code Online (Sandbox Code Playgroud)