Reputation:
I got a little problem since I'm unable to create a simple setPos animation by overriding the setPos method like this:
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()
Thanks in advance, b52
Upvotes: 0
Views: 735
Reputation: 346
@robe: QPropertyAnimation requires the declaring class to be an QObject and I believe QGraphicsItem is not.
Upvotes: 1
Reputation: 10953
Why not use QPropertyAnimation?. With this class you can create animations for any properties of objects.
QPropertyAnimation * animationPos = new QPropertyAnimation(Object, propertyName);
animationPos->setDuration(miliseconds);
animationPos->setStarValue(startValueForProperty);
animationsPos->setEndValue(endValueForProperty);
You should try and you will avoid many conflicts.
Upvotes: 0