Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. QPropertyAnimation use so much system resource when using to create a simple Indeterminate Progressbar

QPropertyAnimation use so much system resource when using to create a simple Indeterminate Progressbar

Scheduled Pinned Locked Moved Unsolved Qt for Python
6 Posts 3 Posters 774 Views 3 Watching
  • 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.
  • S Offline
    S Offline
    saeid0034
    wrote on last edited by
    #1

    hi, Im creating a simple progress bar for my program, I also need it to support an Indeterminate mode, so what I did for it is using QPropertyAnimation to create a offset in infinite loop, and then draw the progress bar based of that
    here is a code snippet from what I have

    class QProgressDelegate(QObject):
        def __init__(self, _parent):
            super().__init__()
            self.m_progress = _parent
            self.m_offset = 0
    
        def get_offset(self):
            return self.m_offset
    
        def set_offset(self, value:float):
            self.m_offset = value
            self.m_progress.update()
    
        offset = Property(float, get_offset, set_offset)
    
    # and then use it like this
        self.delegate = QProgressDelegate(self)
    
        self.animation = QPropertyAnimation(self)
        self.animation.setPropertyName(b"offset")
        self.animation.setTargetObject(self.delegate)
        self.animation.setStartValue(0)
        self.animation.setEndValue(1)
        self.animation.setDuration(1000)
        self.animation.setLoopCount(-1)
    
    # in paint event
        ...
        painter.drawRect(self.delegate.offset*self.width()*2-self.width(), 0, self.width(), self.height())
        ...
    
    

    but the problem is, its use like 10% of cpu when running, and I think its too much... so Im thinking maybe I'm doing it wrong? if yes can anyone point me to a better way?

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Why not just use the standard QProgressBar procedure for "infinite bar" ?

      As the doc says, set both minimum and maximum to 0 and voila, you have a busy indicator.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      S 1 Reply Last reply
      0
      • SGaistS SGaist

        Hi,

        Why not just use the standard QProgressBar procedure for "infinite bar" ?

        As the doc says, set both minimum and maximum to 0 and voila, you have a busy indicator.

        S Offline
        S Offline
        saeid0034
        wrote on last edited by
        #3

        @SGaist because I can make it more beautiful in this way, and also it can suit my needs a little better
        Progress Bar
        I'm not sure if I can achieve something like this with stylesheet...

        1 Reply Last reply
        0
        • S Offline
          S Offline
          SimonSchroeder
          wrote on last edited by
          #4

          @saeid0034 said in QPropertyAnimation use so much system resource when using to create a simple Indeterminate Progressbar:

          but the problem is, its use like 10% of cpu when running, and I think its too much... so Im thinking maybe I'm doing it wrong?

          In general, I expect QPropertyAnimation to be used for short animations. It is likely that it will just run whenever the event queue is idle to make animations as smooth as possible. If you don't have anything else running, it might use up a whole core (is 10% of a single core or all cores together?).

          If this is actually the problem then I would suggest to use a QTimer with 10ms or 50ms resolution and drop the QPropertyAnimation altogether. (Remember 60Hz is about 16ms and even 30Hz is probably smooth enough.)

          S 1 Reply Last reply
          3
          • S SimonSchroeder

            @saeid0034 said in QPropertyAnimation use so much system resource when using to create a simple Indeterminate Progressbar:

            but the problem is, its use like 10% of cpu when running, and I think its too much... so Im thinking maybe I'm doing it wrong?

            In general, I expect QPropertyAnimation to be used for short animations. It is likely that it will just run whenever the event queue is idle to make animations as smooth as possible. If you don't have anything else running, it might use up a whole core (is 10% of a single core or all cores together?).

            If this is actually the problem then I would suggest to use a QTimer with 10ms or 50ms resolution and drop the QPropertyAnimation altogether. (Remember 60Hz is about 16ms and even 30Hz is probably smooth enough.)

            S Offline
            S Offline
            saeid0034
            wrote on last edited by
            #5

            @SimonSchroeder thank you for reply
            I tried to create a custom progress bar with stylesheet, but result was not what I after...
            about QTimer, tbh I dont know how can I use it instead of QPropertyAnimation...
            I mean can I used like how I use QPropertyAnimation? I mean use it to set the QProperty?

            1 Reply Last reply
            0
            • S Offline
              S Offline
              SimonSchroeder
              wrote on last edited by
              #6

              @saeid0034 said in QPropertyAnimation use so much system resource when using to create a simple Indeterminate Progressbar:

              I mean can I used like how I use QPropertyAnimation? I mean use it to set the QProperty?

              Yes, that is exactly right that when the QTimer times out you compute the offset based on the elapsed time and then set the QProperty accordingly.

              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