[Interest] WA_NoSystemBackground vs WA_OpaquePaintEvent

Bo Thorsen bo at vikingsoft.eu
Thu Jan 22 07:59:54 CET 2015


Hi Philippe,Den 21-01-2015 kl. 15:32 skrev Philippe:
> The difference between these two modes is not obvious.
> When should we use *WA_NoSystemBackground* instead of *WE_OpaquePaintEvent*,
> and reciprocally?
> When should we use both?
> I could not get any clear hint while searching through the Qt source...

WA_NoSystemBackground tells QWidget that it should not fill the window 
with the standard widget background. If this is not set, it's possible 
that the paint of a widget is opaque. Qt tries to figure this out 
automatically.

WA_OpaquePaintEvent says to QWidget that you know for a fact that your 
painting of the window will fill up everything. The widget uses this 
knowledge to optimize out some of the things it does before calling the 
widget paintEvent (filling the background is one).

WA_NoSystemBackground doesn't say that your painting of the widget will 
cover the widget completely. This allows you to do some extra 
transparency in your widgets or windows.

If you have set WA_OpaquePaintEvent you don't really need 
WA_NoSystemBackground because the effect is covered. Or that is at least 
what it looks like when I look at the current sources. I normally set 
both anyway, as there might be some subtle difference in future versions.

WA_OpaquePaintEvent is all about optimization. For a lot of custom 
widgets it's not really necessary to worry about them. Of course, we 
don't like to waste cpu cycles, but the painting system in Qt is so fast 
that if this is a small widget you are not going to see any difference. 
But if your painting of the widget does fill the entire widget, you 
should set this.

WA_NoSystemBackground is not about optimization, it is a control you 
have to set whether Qt will paint something on the widget before your 
paintEvent is called.

I hope this helps.

Bo Thorsen,
Director, Viking Software.

-- 
Viking Software
Qt and C++ developers for hire
http://www.vikingsoft.eu



More information about the Interest mailing list