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) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
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();
}
MainWindow::~MainWindow()
{
delete ui;
}@
-
Hi,
Looks like you are setting 200 times a different position but at the same point in time
-
So again, 200 different positions at the same point in time. You give 0.2 as the step for every position.
-
Please, go read QGraphicsItemAnimation's documentation, it's explained in the Detailed Description with a code sample