Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-19110

improvement CPU usage at QProgressBar call setStyleSheet("") method

    XMLWordPrintable

Details

    • ecd78168271cfe71715e074a50752712f4aa3229

    Description

      If one from parent widget of QProgressBar widget have not empty style sheet property (ex., "QWidget{}") repeating calls setStyleSheet("") method of the QProgressBar widget leads to a gradual increasing of CPU usage until capture one core.
      Process Explorer show that main thread of process captures CPU time exactly.

      ============ Code for reproduction ===========

      //-------------------- File main.cpp -----------------------------
      #include <QtGui/QApplication>
      #include <QWidget>
      #include <QProgressBar>

      #include "stylesheettimer.h"

      int main(int argc, char *argv[])
      {
      QApplication a(argc, argv);
      QWidget main;
      main.setStyleSheet("QWidget{}");

      QProgressBar* pb = new QProgressBar(&main);
      main.show();

      TStyleSheetTimer ssTimer(*pb); //for repeating calls pb->setSyleSheet

      return a.exec();
      }

      //---------------------- File stylesheettimer.h --------------
      #define STYLESHEETTIMER_H

      #include <QTimer>
      #include <QWidget>

      class TStyleSheetTimer : public QTimer
      {
      Q_OBJECT

      public:
      TStyleSheetTimer(QWidget& stylewidget)
      : QTimer()
      , m_stylewidget(stylewidget)

      { connect(this, SIGNAL(timeout()), this, SLOT(onTimer())); start(30); //start timer }

      private slots:
      void onTimer()

      { m_stylewidget.setStyleSheet(""); }

      private:
      QWidget& m_stylewidget;
      };

      #endif // STYLESHEETTIMER_H

      ============ Code for reproduction finish ===========

      Note 1: Passing "main" object (that have non-empty SS) to ssTimer constructor do not lead to increasing of CPU usage.
      Note 2: Replacing empty argument value "" by valid CSS string (ex., "QProgressBar{}"

      Same effect observed for applying empty CSS string to one from ProgressBar-widget's intermediate parents if the parent have empty style sheet property.
      Code below creates few parents and leads to the increasing of CPU usage.

      ===========
      int main(int argc, char *argv[])
      {
      QApplication a(argc, argv);
      QWidget main;

      QWidget* child = new QWidget(&main);
      child->setStyleSheet("QWidget{}");

      QWidget* child2 = new QWidget(child);
      QProgressBar* pb = new QProgressBar(child2);

      main.show();

      TStyleSheetTimer ssTimer(*child2);

      return a.exec();
      }
      ==============
      Note 1: Passing "child" object (that have non-empty SS) to ssTimer constructor do not lead to increasing of CPU usage.

      Attachments

        1. main.cpp
          0.7 kB
        2. QtStyleSheetBug.pro
          0.3 kB
        3. stylesheettimer.h
          0.5 kB
        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            frederik Frederik Gladhorn
            adil Adil
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes