Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Multi instances of QPropertyAnimation cost so much of UC

Multi instances of QPropertyAnimation cost so much of UC

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 3 Posters 825 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • SamurayHS Offline
    SamurayHS Offline
    SamurayH
    wrote on last edited by
    #1

    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

    "قال رسول الله صلى الله عليه وسلم : " أحب الناس إلى الله أنفعهم للناس

    jsulmJ 1 Reply Last reply
    0
    • SamurayHS SamurayH

      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

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

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

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      SamurayHS 1 Reply Last reply
      0
      • jsulmJ jsulm

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

        SamurayHS Offline
        SamurayHS Offline
        SamurayH
        wrote on last edited by
        #3

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

        "قال رسول الله صلى الله عليه وسلم : " أحب الناس إلى الله أنفعهم للناس

        J.HilkJ 1 Reply Last reply
        0
        • SamurayHS SamurayH

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

          J.HilkJ Offline
          J.HilkJ Offline
          J.Hilk
          Moderators
          wrote on last edited by J.Hilk
          #4

          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 :-)


          Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


          Q: What's that?
          A: It's blue light.
          Q: What does it do?
          A: It turns blue.

          SamurayHS 1 Reply Last reply
          3
          • J.HilkJ J.Hilk

            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 :-)

            SamurayHS Offline
            SamurayHS Offline
            SamurayH
            wrote on last edited by
            #5

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

            "قال رسول الله صلى الله عليه وسلم : " أحب الناس إلى الله أنفعهم للناس

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved