[Qt-interest] Trying To Understand Transparent Background
Girish Ramakrishnan
girish at forwardbias.in
Mon Oct 5 10:05:08 CEST 2009
Cheung Yik Pang wrote:
> Girish Ramakrishnan wrote:
>> Cheung Yik Pang wrote:
>>
>>> 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?
>>>
>>>
>>
>> That's correct. Here's how I can explain the situation in the X11 world.
>> With WA_TranslucentBackground, you ask Qt to choose ARGB visuals for
>> your application window (I think in the Windows world it's called a
>> 'transparent' layer or something). Without ARGB visuals and a
>> compositing windowing manager, top level transparency does not work.
>>
>> Now, you can argue that you want setting a Qt::transparent background to
>> automatically imply WA_TranslucentBackground but the fact is that it
>> isn't that way :) Qt simply hasn't been special cased for tlw/windows
>> having a autofillbackground with a non-opaque color. You can report a
>> bug, if you like.
>>
>
> Ah, so WA_TranslucentBackground affects windows management, instead of
> the widget itself. That explains a lot. Thanks :)
>
>
>>
>>> 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?
>>>
>>>
>>
>> As I said above, autoFillBackground with non-opaque colors doesn't work
>> on tlw/windows. The consequence is that in the absence of argb visuals,
>> your background is basically garbage since your app doesn't clear the
>> existing background after expose.
>>
>
> So I take this as: If the native window manager is not aware of the
> alpha channel of the widget, whatever native call fillRect() maps to
> will take no effect for non-opaque colors. Right?
>
Almost right. It does have an effect, you just end up painting a
transparent color over garbage :) You can verify this is painting with
some transparent color (you should cause I haven't :)).
Girish
More information about the Qt-interest-old
mailing list