1

I created a widget that serves as some kind of popup window und hence should have a drop shadow all around to optically raise it from the background. I initialize the drop shadow effect in the constructor of my popup widget as follows:

dropshadow = new QGraphicsDropShadowEffect(this);
dropshadow->setBlurRadius(32);
dropshadow->setColor(QColor("#121212"));
dropshadow->setOffset(0,0);
setGraphicsEffect(dropshadow);

The application runs on an embedded system with an Intel Atom CPU, a custom Linux distribution, Qt v4.7.3 running with a qws server. When I disable the drop shadow, my cpu usage is less than 10% when the GUI is idle. Enabling the drop shadow raises the cpu usage to more than 80%. Profiling the app shows that most of the CPU time is spent within libQtGui.so.4.7.3.

Does anyone have an idea why the cpu usage explodes like this even though there is absolutely nothing going on in the GUI, not even mouse movement?

Edit: Changing the size of the popup changes the amount of cpu usage. Reducing the size to a quarter reduces the cpu usage to about a quarter. Very strange.

arne
  • 4,514
  • 1
  • 28
  • 47
  • 1
    Not strange. Probably the implementation of the drop shadow does work that increases with the amount of pixels shadowed :) And what do you mean by "idle"? Either Qt/E redraws the screen all the time or something is triggering redraws, methinks. – Torp Sep 20 '11 at 13:51
  • Well I believe Qt is smart enough not to redraw all the time, especially in embedded systems, as long as nothing changes, i.e. no mouse movement, no changes in the visible widgets etc. Otherwise, CPU usage would be at 100% all the time, would it not? – arne Sep 21 '11 at 04:49
  • Is there a blinking cursor inside your popup ? – alexisdm Sep 25 '11 at 13:53
  • Nope. There's just a QLabel and a couple of buttons. Is I already said, showing the popup without drop shadow does not take abnormal CPU time. – arne Sep 26 '11 at 04:51

1 Answers1

1

The problem was only partly with the drop shadow. It seems that repainting a drop shadow requires quite a lot of CPU time - which is OK if it is not redrawn too often. The problem was simple really. The widget that was behind this popup was redrawn four to five times per second and hence, the popup needed to be redrawn, too. This swallowed huge amounts of CPU time. The solution is equally simple: Avoid repaint events if nothing really changes on screen.

arne
  • 4,514
  • 1
  • 28
  • 47
  • Unfortunately the drop shadow also causes high CPU load if things get painted within the popup, e.g. a blinking cursor. Although the drop shadow does not change it gets repainted all the time. – Ber Jan 22 '14 at 10:08
  • @Ber: How unfortunate. I didn't know and didn't notice at the time. – arne Jan 22 '14 at 10:19