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;
    }

    @


  • Lifetime Qt Champion

    Hi,

    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)
    animation->setPosAt(0.2, QPointF(i,200));
    @


  • Lifetime Qt Champion

    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?


  • Lifetime Qt Champion

    Please, go read QGraphicsItemAnimation's documentation, it's explained in the Detailed Description with a code sample


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.