Multi instances of QPropertyAnimation cost so much of UC
-
Hey everyone,
I'm using in my project a custom label called movLabel (subclass of QWidget), which contains a QLabel able to move (horizontally) when its text overflows. I'm using to move the QLabel, QPropertyAnimation. Here is a code snippets:void movLabel::Move() { int dur = ((double)(m_label->width() - width()) / (double)READ_SPEED) * 1000; QSequentialAnimationGroup *group = new QSequentialAnimationGroup; group->addAnimation(StaticAnim::animPos(m_label, QPoint(0,0), QPoint(width() - m_label->width(), m_label->y()), dur)); group->addPause(2000); group->addAnimation(StaticAnim::animPos(m_label, QPoint(width() - m_label->width(),m_label->y()), QPoint(0, 0), dur)); group->addPause(2000); group->start(QPropertyAnimation::DeleteWhenStopped); connect(group, SIGNAL(finished()), this, SLOT(Move())); }
Note that StaticAnim::animPos return an initialized QPropertyAnimation.
The problem is that I'm not controlling the number of created movLabel, consequently the number of QPropertyAnimations, which cost a lot of UC (CPU).
I don't know if it's possible to handle multi object animations using Qt Animation Framework, or I should use a global TIMER.
I will appreciate your advice -
@SamurayH said in Multi instances of QPropertyAnimation cost so much of UC:
connect(group, SIGNAL(finished()), this, SLOT(Move()));
Why do you connect finished() to Move()? That means: when animation finishes you start it again, right?
-
hi @SamurayH
I think what you're doing is a bit overkill for what you actually want to archive.
I think you want a Marquee element like scrolling text in Qt.A quick google search resulted in this stackoverflow thread:
https://stackoverflow.com/questions/10651514/text-scrolling-marquee-in-qlabelthat has 4 different working Marquee classes in it :-)