[英]PyQt5 Animation
我正在嘗試使用 PyQt5 QPropertyAnimation class 為在屏幕上移動的車輛(x 方向)設置動畫。 我正在使用 QEasingCurve 的交換功能,但應用程序不斷崩潰。
原因:我想使用 Swap 來改變曲線的行為,並在車輛啟動后減慢或加速車輛。
TypeError: swap(self, QEasingCurve): argument 1 has unexpected type 'Type'
這是我擁有的代碼的 animation 部分。
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 個 QEasingCurve 的特征:
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)
# ...
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.