Results 1 to 14 of 14

Thread: QGraphicsItemAnimation and QTimeLine

  1. #1
    Join Date
    Nov 2007
    Posts
    291
    Thanks
    85
    Thanked 1 Time in 1 Post

    Default QGraphicsItemAnimation and QTimeLine

    hi
    the following code works .
    but how does the for loop is executed after timer has started(after the for loop the timer is started)

    Qt Code:
    1. #include <QtGui>
    2.  
    3. int main(int argc, char *argv[])
    4. {
    5. QApplication a(argc, argv);
    6. QGraphicsItem *ball = new QGraphicsEllipseItem(0, 0, 20, 20);
    7.  
    8. QTimeLine *timer = new QTimeLine(5000);
    9. timer->setFrameRange(0, 100);
    10.  
    11. animation->setItem(ball);
    12. animation->setTimeLine(timer);
    13.  
    14. for (int i = 0; i < 200; ++i)
    15. animation->setPosAt(i / 200.0, QPointF(i, i));
    16.  
    17. scene->setSceneRect(0, 0, 250, 250);
    18. scene->addItem(ball);
    19.  
    20. QGraphicsView *view = new QGraphicsView(scene);
    21. view->show();
    22.  
    23. timer->start();
    24. return a.exec();
    25. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QGraphicsItemAnimation and QTimeLine

    What do you mean is later executed? The loop initializes how QGraphicsItemAnimation will perform after the QTimeLine is started.
    J-P Nurmi

  3. #3
    Join Date
    Nov 2007
    Posts
    291
    Thanks
    85
    Thanked 1 Time in 1 Post

    Default Re: QGraphicsItemAnimation and QTimeLine

    What do you mean is later executed?
    how does the control goes back to for loop(line 15) after timer has started (line 25) .

  4. #4
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QGraphicsItemAnimation and QTimeLine

    Quote Originally Posted by babu198649 View Post
    how does the control goes back to for loop(line 15) after timer has started (line 25) .
    You got it all wrong.
    The control will not be passed back to the for loop.

    Qt Code:
    1. for (int i = 0; i < 200; ++i)
    2. animation->setPosAt(i / 200.0, QPointF(i, i));
    To copy to clipboard, switch view to plain text mode 
    All this code does is to store 200 positions inside the animation object.
    Once the timer is started, the ball graphics item will be moved sequentially at the positions you previously stored inside the animation object. This will give you an impression of animation.
    So that's pretty much how it works.

  5. The following user says thank you to marcel for this useful post:

    babu198649 (29th December 2007)

  6. #5
    Join Date
    Nov 2007
    Posts
    291
    Thanks
    85
    Thanked 1 Time in 1 Post

    Default Re: QGraphicsItemAnimation and QTimeLine

    thanks
    when the value of the step in the setPosAt ( qreal step, const QPointF & point ) function is smaller(ie.nearer to zero) the animation occurs faster(i.e duration of animation is less) and when the value of step is set to bigger value (nearer to or equal to one ) , the animation animates slowly .

    then why do we need the QTimeLine when we can control the duration of animation using setPosAt ( qreal step, const QPointF & point ).
    Last edited by babu198649; 29th December 2007 at 11:09.

  7. #6
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QGraphicsItemAnimation and QTimeLine

    Quote Originally Posted by babu198649 View Post
    when the value of the step in the setPosAt ( qreal step, const QPointF & point ) function is smaller(ie.nearer to zero) the animation occurs faster(i.e duration of animation is less) and when the value of step is set to bigger value (nearer to or equal to one ) , the animation animates slowly .
    QTimeLine::curveShape
    Quote Originally Posted by babu198649 View Post
    then why do we need the QTimeLine when we can control the duration of animation using setPosAt ( qreal step, const QPointF & point ).
    These are positions at given step. QTimeLine controls the duration and speed of the animation.
    J-P Nurmi

  8. #7
    Join Date
    Aug 2007
    Location
    Gorakhpur, India
    Posts
    254
    Thanks
    8
    Thanked 14 Times in 14 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: QGraphicsItemAnimation and QTimeLine

    Quote Originally Posted by babu198649 View Post
    thanks
    when the value of the step in the setPosAt ( qreal step, const QPointF & point ) function is smaller(ie.nearer to zero) the animation occurs faster(i.e duration of animation is less) and when the value of step is set to bigger value (nearer to or equal to one ) , the animation animates slowly .

    then why do we need the QTimeLine when we can control the duration of animation using setPosAt ( qreal step, const QPointF & point ).
    For one pass of complete animation QTimeLine is used. It is a time (in millisec)for one pass of animation of object.
    Anurag Shukla
    A man who never makes mistake is the man who never does anything! Theodre Rosvelt!

  9. #8
    Join Date
    Nov 2007
    Posts
    291
    Thanks
    85
    Thanked 1 Time in 1 Post

    Default Re: QGraphicsItemAnimation and QTimeLine

    hi
    QTimeLine controls the duration and speed of the animation.
    step can decrease the duration of the animation.

    Does step decides the sequence in which the item has to be moved .

  10. #9
    Join Date
    Aug 2006
    Location
    Bangalore,India
    Posts
    419
    Thanks
    37
    Thanked 53 Times in 40 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: QGraphicsItemAnimation and QTimeLine

    Basically timeline works on interpolation and extrapolation concepts.

    It is like the animation's total path is represented as a function f(x) where x is time.
    Then we provide 'f(x)' values for our own set of 'x' values.
    For example, f(x) should represent (10,10) when x = 5ms
    f(x) should represent (15, 15) when x = 10 ms.
    That is, each 5ms, 10ms is time step.

    Based on these values the f(x) is determined generally. Now a timer is started to emit signals at regular intervals and based on this time, the f(x) is calculated. Setting the item's position to value returned by f(x) at those specific intervals called by signal creates a feeling of animation. This is what QGraphicsAnimation does.

    P.S:
    I might be wrong. If so please correct me as these concepts are new even to me.
    The biggest difference between time and space is that you can't reuse time.
    -- Merrick Furst

  11. #10
    Join Date
    Nov 2007
    Posts
    291
    Thanks
    85
    Thanked 1 Time in 1 Post

    Default Re: QGraphicsItemAnimation and QTimeLine

    thanks Gopala Krishna

    After experimenting i now understood that the animation will occur through out the duration(which is set using QTimeLine) only when the step value is set to both 0 &1.

    otherwise,
    if the step value is set to greater than zero and to 1 then, the animation gets started after a delay.
    e.x
    animation->setPosAt(0.5,QPointF(0,0));
    animation->setPosAt(1, QPointF(0,550)) //the animation will start after a delay;
    similarly, if the step value is set to zero and less than one then, the animation ends before the time to which it has set.

    ex.
    animation->setPosAt(0.00,QPointF(0,0));
    animation->setPosAt(0.80, QPointF(0,550)); //animation ends earlier than the time set.
    the problem is when there are multiple points to be set for an animation ,the speed of the animation differs based on the difference between the step values of two points.

    how to animate an item at constant speed .

  12. #11
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QGraphicsItemAnimation and QTimeLine

    Steps lie between 0.0 and 1.0 where 0.0 is at the beginning of the animation and 1.0 is in the end.
    Qt Code:
    1. animation->setPosAt(0.0, QPointF(0,0)); // animation will move the item to (0,0) at step 0.0 (beginning)
    2. animation->setPosAt(0.25, QPointF(1,1)); // animation will move the item to (1,1) at step 0.25 (25% completed)
    3. animation->setPosAt(0.5, QPointF(2,2)); // animation will move the item to (2,2) at step 0.5 (midway)
    4. animation->setPosAt(0.75, QPointF(3,3)); // animation will move the item to (3,3) at step 0.75 (75% completed)
    5. animation->setPosAt(1.0, QPointF(4,4)); // animation will move the item to (4,4) at step 1.0 (end)
    To copy to clipboard, switch view to plain text mode 
    How long it will take to reach these steps is up to the attached QTimeLine. GraphicsItemAnimation does not care when these steps are reached. One can even set a certain step by hand via QGraphicsItemAnimation::setStep().
    J-P Nurmi

  13. #12
    Join Date
    Nov 2007
    Posts
    291
    Thanks
    85
    Thanked 1 Time in 1 Post

    Default Re: QGraphicsItemAnimation and QTimeLine

    thank u jpn
    how to animate a sub-classed widget .

  14. #13
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QGraphicsItemAnimation and QTimeLine

    Quote Originally Posted by babu198649 View Post
    how to animate a sub-classed widget .
    Sorry, but how is this question related to QGraphicsItemAnimation, the subject of this thread? QGraphicsItemAnimation handles QGraphicsItems, not QWidgets.
    J-P Nurmi

  15. #14
    Join Date
    Nov 2007
    Posts
    291
    Thanks
    85
    Thanked 1 Time in 1 Post

    Default Re: QGraphicsItemAnimation and QTimeLine

    sorry
    i thought all the animation should be done with QGraphicsItemAnimation.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.