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....
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();
QGraphicsTextItem *scrItem = new QGraphicsTextItem(txtScrollEdit->toPlainText());
QDir::setCurrent(QDir::currentPath ()+"/media");
QGraphicsScene *scene=new QGraphicsScene();
scrItem->setDefaultTextColor(Qt::red);
scene->setBackgroundBrush(Qt::yellow);
QGraphicsItemAnimation *animation = new QGraphicsItemAnimation;
animation->setItem(scrItem);
float n;
view=new QGraphicsView(scene,btgScrollText);
view->setWindowFlags (Qt::FramelessWindowHint);
scene->addItem(scrItem);
view->setVerticalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
view->setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
view->setCacheMode(QGraphicsView::CacheBackground);
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 = new QTimeLine(tl);
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();
To copy to clipboard, switch view to plain text mode
Thanks in Advance!
Bookmarks