Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Not able to animate the ball at row 200 (solved)
Forum Updated to NodeBB v4.3 + New Features

Not able to animate the ball at row 200 (solved)

Scheduled Pinned Locked Moved General and Desktop
6 Posts 2 Posters 1.4k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    houmingc
    wrote on last edited by
    #1

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

    @

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Looks like you are setting 200 times a different position but at the same point in time

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • H Offline
        H Offline
        houmingc
        wrote on last edited by
        #3

        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));
        @

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          So again, 200 different positions at the same point in time. You give 0.2 as the step for every position.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • H Offline
            H Offline
            houmingc
            wrote on last edited by
            #5

            can please show few line of code to meet the objective?

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

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

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved