I’m having trouble understanding how QGraphicsItemAnimation’s setScaleAt function works. Here’s the code I’m using:
QGraphicsItem *item=scene.addEllipse(400, 300, 100, 100, QPen(), QBrush(Qt::SolidPattern));
QTimeLine *timeline=new QTimeLine(3000);
timeline->setFrameRange(0, 100);
QGraphicsItemAnimation *animation=new QGraphicsItemAnimation;
animation->setItem(item);
animation->setTimeLine(timeline);
for (int i=0; i<100; i++) {
animation->setScaleAt(i/100.0, i/100.0, i/100.0);
}
connect(timeline, SIGNAL(valueChanged(qreal)), animation, SLOT(setStep(qreal)));
timeline->start();
All I want it to do is display a dot in the middle of the screen, then have it expand to a circle over 3 seconds. What this code gets me is a dot that appears in the upper left corner, then grows and simultaneously moves to the middle. I tried to compensate by setting the position at each step, but this seems pretty convoluted. There’s got to be a cleaner way to do this.
Also, the original item is displayed for a split second before the animation starts, is there any way to hide it by default, then display for the animation?
Thanks in advance.
This is because the origin of the transformation is in the top left corner of the item. You should use something like addEllipse(-50, -50, 100, 100) instead so that the origin is in the center. Of course, you need to position the item somewhere where it makes sense.