Results 1 to 2 of 2

Thread: Constant velocity problem for variable length Text Animation?

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

    Question Constant velocity problem for variable length Text Animation?

    Dear Everyone!

    I am animating text using QTimeline & QGraphicsItem Class. I am facing problem of varing velocity (speed of text) of text if text size is not equal for multiple animation. I want to constant velocity (animation speed constant) for variable length text. What can I do for this.

    I am putting the code for that....
    Qt Code:
    1. QGraphicsTextItem *scrItem = new QGraphicsTextItem(txtScrollEdit->toPlainText());
    2. QDir::setCurrent(QDir::currentPath ()+"/media");
    3.  
    4. scrItem->setDefaultTextColor(Qt::red);
    5. scene->setBackgroundBrush(Qt::yellow);
    6.  
    7.  
    8.  
    9. animation->setItem(scrItem);
    10.  
    11.  
    12. float n;
    13. view=new QGraphicsView(scene,btgScrollText);
    14. view->setWindowFlags (Qt::FramelessWindowHint);
    15.  
    16. scene->addItem(scrItem);
    17.  
    18. view->setVerticalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
    19. view->setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
    20. view->setCacheMode(QGraphicsView::CacheBackground);
    21.  
    22. n=355; /*Width of txtScrollEdit TextEdit*/
    23.  
    24. qreal h=scene->height()/2-scrItem->boundingRect().height()/2;
    25.  
    26.  
    27. register int velocity=40;
    28. register int tl=n*velocity;
    29.  
    30. timer = new QTimeLine(tl);
    31.  
    32.  
    33. timer->setCurveShape(QTimeLine::LinearCurve);
    34. timer->setLoopCount(0);
    35. animation->setTimeLine(timer);
    36. animation1->setTimeLine(timer);
    37.  
    38.  
    39. register int scrItembrw=scrItem->boundingRect().width();
    40. for (register int i=0; i<(n+scrItembrw); i=i+1)
    41. {
    42. register QPointF p(0,h); //sets the position of scrItem
    43. p.setX(n-i);
    44. p.setY(h);
    45. animation->setPosAt(i/(n+scrItembrw),p);
    46.  
    47. }//end for
    48.  
    49. view->show();
    50. timer->start();
    To copy to clipboard, switch view to plain text mode 
    Thanks in Advance!
    Anurag Shukla
    A man who never makes mistake is the man who never does anything! Theodre Rosvelt!

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,709
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Constant velocity problem for variable length Text Animation?

    Your problem is that your animation "frames" number is a function of the text size.
    You should have that as a constant, if you want the same speed effect.
    Qt Code:
    1. register int scrItembrw=scrItem->boundingRect().width();
    2. for (register int i=0; i<(n+scrItembrw) /*this should be a constant*/; i=i+1)
    3. {
    4. register QPointF p(0,h); //sets the position of scrItem
    5. p.setX(n-i);
    6. p.setY(h);
    7. animation->setPosAt(i/(n+scrItembrw),p);
    8.  
    9. }//end for
    To copy to clipboard, switch view to plain text mode 
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

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.