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....
Code:
QDir::setCurrent(QDir::currentPath ()+"/media");
scrItem->setDefaultTextColor(Qt::red);
scene->setBackgroundBrush(Qt::yellow);
animation->setItem(scrItem);
float n;
view->setWindowFlags (Qt::FramelessWindowHint);
scene->addItem(scrItem);
view->setVerticalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
view->setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
n=355; /*Width of txtScrollEdit TextEdit*/
qreal h=scene->height()/2-scrItem->boundingRect().height()/2;
register int velocity=40;
register int tl=n*velocity;
timer
->setCurveShape
(QTimeLine::LinearCurve);
timer->setLoopCount(0);
animation->setTimeLine(timer);
animation1->setTimeLine(timer);
register int scrItembrw=scrItem->boundingRect().width();
for (register int i=0; i<(n+scrItembrw); i=i+1)
{
register QPointF p
(0,h
);
//sets the position of scrItem p.setX(n-i);
p.setY(h);
animation->setPosAt(i/(n+scrItembrw),p);
}//end for
view->show();
timer->start();
Thanks in Advance!
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.
Code:
register int scrItembrw=scrItem->boundingRect().width();
for (register int i=0; i<(n+scrItembrw) /*this should be a constant*/; i=i+1)
{
register QPointF p
(0,h
);
//sets the position of scrItem p.setX(n-i);
p.setY(h);
animation->setPosAt(i/(n+scrItembrw),p);
}//end for