[Qt-interest] Trying To Understand Transparent Background

Francisco Ares frares at gmail.com
Mon Oct 5 12:08:49 CEST 2009


On Mon, Oct 5, 2009 at 5:05 AM, Girish Ramakrishnan
<girish at forwardbias.in>wrote:

> 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
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest
>


There's an article in Qt Quarterly #30, along with a ZIPed sample code, that
may help: http://doc.trolltech.com/qq/

Francisco

-- 
"If you have an apple and I have an apple and we exchange apples then you
and I will still each have one apple. But if you have an idea and I have one
idea and we exchange these ideas, then each of us will have two ideas." -
George Bernard Shaw
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20091005/7592ca2b/attachment.html 


More information about the Qt-interest-old mailing list