[Qt-interest] Trying To Understand Transparent Background

Cheung Yik Pang yp.cheung at valueplatforms.com
Mon Oct 5 05:48:57 CEST 2009


Girish Ramakrishnan wrote:
> Cheung Yik Pang wrote:
>   
>> Hi all,
>>
>> I have a questions about using transparent color as background color of
>> widgets.
>>
>> My little test program basically move a blue widget around in a
>> transparent widget for every 5 seconds.  Both widgets had
>> autoFillBackground set to true.
>>
>> My expectation is that when the blue widget moved from area A to area B
>> in the parent widget, area A will be cleared with transparent color and
>> area B will be blue.  But what I get is both area A and area B became blue.
>>
>> I have tried the new 4.5.3 and the 4.6 git head on Windows.  Both have
>> the same result.
>>     
>
> What you are seeing is expected behavior. Maybe you can tell us what are
> you trying to achieve? Are you trying to make your window transparent
> i.e one can see through your window? If so, this is not the correct
> approach - see WA_TranslucentWindow.
>
> Girish
>   

Thank you for replying.

And yes, I am trying to have a transparent window.  Frankly, I am a 
little bit confused.

Qt::WA_TranslucentBackground implies WA_NoSystemBackground, which means 
I need to fill the background with Qt::transparent in every 
paintEvent(), right?  But how is it different from 
setAutoFillBackground(true) with QPalette::Window set to Qt::transparent?

And let's forget about the transparent window thing for a minute.  Why 
does Qt refuse to fill the background if QPalette::Window is 
Qt::tranpsarent, but not Qt::black?

Regards,
Cheung



More information about the Qt-interest-old mailing list