PDA

View Full Version : Mac OS X Top-Level Transparent Widgets



tinsuke
17th October 2008, 17:01
Hi folks,

I'd like to write an application (Windows, Linux and Mac OS X) having a (per pixel) transparent top-level widget.

Some might say that I can use masks for that. But I can't. The fact is that the mask would change very often (I have some animated widgets) and updating a widget mask costs way TOO much!

Ok, googling for it, I've found this: http://trolltech.com/developer/faqs/faq.2007-02-08.3940505976

In short terms, the FAQ page says that Qt doesn't support this, but there are platform-dependent ways to achieve this goal, and I'd like to implement them!

For Linux, it's pretty much straighforward. Instancing an QApplication with a X Display that supports Composite gives you the ability to clear a widget on its paintEvent() to Qt::transparent. You can, then, paint any widgets on it and you'll have a "floating widgets" visual (this is what I'm looking for).

On Windows, it says to use the UpdateLayeredWindow() function :confused:, DOT. Wow, great, this is the magical function that will save my neck! Hell God, how to use it???
I'd like to thank the kernel_panic user, who used this function on his QSkinWindows to achieve transparency. The method is very likely the Linux one: on paintEvent(), create a QPixmap, clear it to Qt::transparent, draw your child widgets on it, then display it on your widget using UpdateLayeredWindow(). The resultant widget is exactly like I want.

On Mac OS X, you may use the kOverlayWindowClass for this. And my "lost measurement" light just shone brighter than when I read the Windows way... It says that one would have to modify Qt to use this WindowClass. I thought that modding QtGui (src/gui/kernel/qwidget_mac.cpp) to use this WindowClass for EVERY CreateNewWindow call (line 420 for Qt 4.4.3 src) would work and I would only have to make my top-level widget have a 0% opacity and draw full-opaque child widgets on top of it to achieve my goal. It just didn't worked AND caused some crashes, geez :p.

There are some Apple samples on how to use kOverlayWindowClass, and the results are windows with the effect I'd like to have. But I don't see a way to integrate a Carbon-created window with my Qt widgets... :crying:

Can anyone help me on how to mod (and use) Qt to achieve this goal OR how to integrate a external Carbon window with Qt widgets?

Thanks in advance!