Not able to animate the ball at row 200 (solved)
setPosAt sets the position of the item at the given step value to the point specified.
iterating i at row 200 not successful, why?
@ animation->setPosAt(0.2, QPointF(i,200));
Could not animate the ball rolling at bottom row.
It's seems to be moving at an acceleration??
MainWindow::MainWindow(QWidget *parent) :
QGraphicsItem *ball = new QGraphicsEllipseItem(0, 0, 20, 20);
QTimeLine *timer = new QTimeLine(5000); timer->setFrameRange(0, 100); QGraphicsItemAnimation *animation = new QGraphicsItemAnimation; animation->setItem(ball); animation->setTimeLine(timer); for (int i = 0; i < 200; ++i) animation->setPosAt(0.2, QPointF(i,200)); QGraphicsScene *scene = new QGraphicsScene(); scene->setSceneRect(0, 0, 250, 250); scene->addItem(ball); QGraphicsView *view = new QGraphicsView(scene); view->show(); timer->start();
Looks like you are setting 200 times a different position but at the same point in time
No. QPointF::QPointF(qreal x, qreal y)
i am iterating x and setting y at a constant value
for (int i = 0; i < 200; ++i)
So again, 200 different positions at the same point in time. You give 0.2 as the step for every position.
can please show few line of code to meet the objective?
Please, go read QGraphicsItemAnimation's documentation, it's explained in the Detailed Description with a code sample