我正在尝试使用PyQt5 QPropertyAnimation类为在屏幕(x方向)上移动的车辆设置动画。我正在使用QEasingCurve的Swap功能,但应用程序不断崩溃。
原因:我想使用“交换”来更改曲线的行为,并在车辆启动后减慢或加快其速度。
TypeError: swap(self, QEasingCurve): argument 1 has unexpected type 'Type'
这是我的代码中的动画部分。
self.animateTaycan = QPropertyAnimation(self.taycan_Frame, b"geometry")
self.animateTaycan.setDuration(2000)
self.animateTaycan.setStartValue(QRect(self.taycan_Frame.geometry()))
self.animateTaycan.setEndValue(QRect(self.screenWidth - 300, 522, 280, 141))
curve = QEasingCurve()
curve.setType(QEasingCurve.OutSine)
curve.swap(QEasingCurve.InCurve)
self.animateTaycan.setEasingCurve(curve)
self.animateTaycan.start()
交换的目的是交换2个QEasingCurves的特征:
from PyQt5.QtCore import QEasingCurve
curve1 = QEasingCurve(QEasingCurve.OutSine)
curve2 = QEasingCurve(QEasingCurve.InCurve)
assert curve1.type() == QEasingCurve.OutSine
assert curve2.type() == QEasingCurve.InCurve
curve2.swap(curve1)
assert curve1.type() == QEasingCurve.InCurve
assert curve2.type() == QEasingCurve.OutSine
您可以看到:type()
的特性被交换。
但是,在您的情况下,您传递的是QEasingCurve :: Type而不是QEasingCurve生成的错误。
在您的情况下,没有2个QEasingCurve,因此无需进行交换,只需设置一种新的曲线类型:
# ...
curve = QEasingCurve()
curve.setType(QEasingCurve.InCurve)
self.animateTaycan.setEasingCurve(curve)
# ...