When the button is clicked, the frame is moved to the start value in the doAnimation function but does not move to the end value
from PyQt5.QtWidgets import QApplication, QMainWindow, QPushButton, QFrame, QVBoxLayout
from PyQt5.QtCore import Qt, QPropertyAnimation, QRect
import sys
class Window(QMainWindow):
def __init__(self):
super().__init__()
self.setGeometry(100, 100, 680, 500)
button = QPushButton("Start", self)
button.clicked.connect(self.doAnimation)
button.move(30, 30)
self.frame = QFrame(self)
self.frame.setFrameStyle(QFrame.Panel | QFrame.Raised)
self.frame.setGeometry(150, 30, 100, 100)
self.show()
def doAnimation(self):
anim = QPropertyAnimation(self.frame, b"geometry")
anim.setDuration(5000)
anim.setStartValue(QRect(0, 0, 100, 30))
anim.setEndValue(QRect(250, 250, 100, 30))
anim.start()
if __name__ == '__main__':
app = QApplication(sys.argv)
win = Window()
sys.exit(app.exec_())
I tried adding print() to every line in the doAnimation function and expected to not print all of them. The output is that it printed all. What could be the problem?
def doAnimation(self):
print("test")
anim = QPropertyAnimation(self.frame, b"geometry")
print("test")
anim.setDuration(5000)
print("test")
anim.setStartValue(QRect(0, 0, 100, 30))
print("test")
anim.setEndValue(QRect(250, 250, 100, 30))
print("test")
anim.start()
print("test")