相关疑难解决方法(0)

QPropertyAnimation不适用于子窗口小部件

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

我在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)

python animation qt pyqt

3
推荐指数
1
解决办法
2075
查看次数

标签 统计

animation ×1

pyqt ×1

python ×1

qt ×1