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


  • Moderators

    @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?



  • @jsulm
    Yes exactly, it's a loop, so that it will look like this :
    0_1530697045773_lal.gif



  • 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-qlabel

    that has 4 different working Marquee classes in it :-)



  • @J.Hilk
    You're right, I will try timerEvent and startTimer instead.
    Thanks all! Have a nice day.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.