我遇到了一个小问题,因为我无法通过重写 setPos 方法来创建简单的 setPos 动画,如下所示:
def setPos(self, pos):
print('from %s to %s' % (self.scenePos(), pos))
timer = QTimeLine(5000)
timer.setFrameRange(0, 100)
animation = QGraphicsItemAnimation()
animation.setItem(self)
animation.setTimeLine(timer)
x_step = (pos - self.scenePos()).x() / 200
y_step = (pos - self.scenePos()).y() / 200
for i in range(200):
animation.setPosAt(i/200, self.scenePos() + QPointF(i * x_step, i * y_step))
timer.start()
提前致谢, b52