PDA

View Full Version : Adding a QProgressbar makes my app cpu consumption pass from 0% to 80-100% of a core



cgahete
16th January 2014, 14:19
Hi,

I’m adding a small QProgressbar to my app, but now I’m realizing that it is taking almost a core. I’ve read about some bugs related but I cant fix or workaround this issue. Any chances?



int main(int argc, char *argv[])
{
QApplication a(argc, argv);
pruebasqt w;

QGraphicsDropShadowEffect* wndShadow = new QGraphicsDropShadowEffect;
wndShadow->setBlurRadius(9.0);
wndShadow->setColor(QColor(0, 0, 0, 90));
wndShadow->setOffset(5);
w.setGraphicsEffect(wndShadow);

w.setWindowFlags( Qt::FramelessWindowHint | Qt::WindowMinimizeButtonHint);
w.setAttribute(Qt::WA_TranslucentBackground);

w.setStyleSheet("QWidget{ background: red;}");

w.show();
return a.exec();
}

Being “pruebasqt” a default QMainWindow with one QProgressBar. This makes 100% of one core in my computer (An Intel Xeon with 8 cores and 26 Gb RAM)


-QT 4.8.4
-Windows 7

ChrisW67
17th January 2014, 00:16
Odd that you choose not to show the code that actually deals with the progress bar.
Is it just sitting doing nothing, or is the progress bar being updated? How is it being updated?

Does the program behave differently if you omit the graphical effect (lines 6-15)?

cgahete
17th January 2014, 14:44
Hi,

The window is the default one that QT designer creates for me: I create QMainWindow and add one QProgressbar. In fact, the problem appears when combining a QProgressbar and a QGraphicsDropShadowEffect. The QProgressbar is not being updated, the GUI is in idle. Can someone reproduce this?

anda_skoa
18th January 2014, 13:19
One possible cause could be the Windows 7 style progressbar animation, i.e. it somehow triggering recalculation of the graphics effect.
Does it also happen if you do not set the transparency widget attribute?

Cheers,
_

cgahete
20th January 2014, 09:37
Yes, its the same behaviour. The problem comes when combining the graphics effect with a QProgressbar.

cgahete
22nd January 2014, 12:12
Full compilable version:



#include <QtGui/QApplication>
#include <QGraphicsDropShadowEffect>
#include <QProgressbar>



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

QWidget* w = new QWidget();
w->setGeometry(40,40,1600,1000);
QProgressBar* qp = new QProgressBar(w);
qp->setValue(99);

QGraphicsDropShadowEffect* wndShadow = new QGraphicsDropShadowEffect;
w->setGraphicsEffect(wndShadow);

w->show();
return a.exec();
}

anda_skoa
22nd January 2014, 12:56
Aside from the typo (should be #include <QProgressBar>) this works fine with Qt 4.8.6 on Linux.

Try with a different style, e.g. running the program with -style plastique

Cheers,
_

cgahete
22nd January 2014, 15:19
Yes, I've tested other styles (that have no animation on QProgressbar) and no cpu compumption there.