PDA

View Full Version : Transparent Qwidget



naruto_9w
13th January 2009, 08:25
Hi all,

Is it possible to make a QWidget showed (by invoking .show()) with transparent background?

I've read some related articles in the forum, and had tried some methods including:
1. setAttribute(Qt::WA_NoSystemBackground)
2. setStyleSheet("background-color: transparent")
3. In paintEvent: QPixmap pix(size()); pix.fill(Qt::transparent); painter.drawPixmap(0,0,pix);

But no one succeed, I tested above methods within Shaped Clock example (which is under QTDIR/examples/widgets/shapedclock). Under Windows XP, I got a black background, and under Ubuntu 8.10, i got a vague background.

Any sugguestion or help are welcomed, keep waiting online!

aamer4yu
13th January 2009, 08:42
If you want whole of your window to be transparent, you can use QWidget::setWindowOpacity .

It is difficult if u want transparent background and semi-transparent/opaque child widgets.
For that you can refer this thread (http://www.qtcentre.org/forum/f-qt-software-16/t-qskinwindows-classes-9301.html)

naruto_9w
13th January 2009, 08:49
Thanks for your message!
We don't want to make full transparent of the widget, just the background.

Actually, our final destination is to make the background of a WebView widget showed with transparent background, so that we can render some shaped contents on desktop. Somehow like Yahoo! widget effects. Is that possible via Qt?

Sorry for not making my point clear enough.

aamer4yu
13th January 2009, 09:11
I guess you want to draw/write on desktop.
For that you can take snap of desktop, save it on pixmap, and render this pixmap as background .
You can find related examples in the forum.
Also search for shaped clock example, alpha widget example(on qt labs i guess).

This (http://www.qtcentre.org/forum/f-qt-programming-2/t-transparency-setmask-createheuristicmask-createmaskfromcolor-qpixmap-5518.html) might also help you

naruto_9w
13th January 2009, 09:26
Wow, that looks great, i will have a try, many thanks in advance!

naruto_9w
13th January 2009, 13:22
I guess you want to draw/write on desktop.
For that you can take snap of desktop, save it on pixmap, and render this pixmap as background .
You can find related examples in the forum.
Also search for shaped clock example, alpha widget example(on qt labs i guess).

This (http://www.qtcentre.org/forum/f-qt-programming-2/t-transparency-setmask-createheuristicmask-createmaskfromcolor-qpixmap-5518.html) might also help you

I ran this sample code at here (http://www.qtcentre.org/forum/p-transparency-setmask-createheuristicmask-createmaskfromcolor-qpixmap-post28500/postcount4.html)

But it's weird that there shows a transparent window with nothing in it, i expected there should be a sentence of "Qt Centre" on the label, btw, my Qt version is 4.5.0-beta1, is this the reason for this problem?

naruto_9w
13th January 2009, 13:33
My god, the sample works well on Windows... frameless... only label text shown on screen...
Totally confused! Anything more to be noticed under X11? Btw, i'm using Ubuntu 8.10 now.

Thanks in adv!

aamer4yu
13th January 2009, 16:09
I dont know about X11, but u can see ARGB window in Trolltech labs --> dojo examples.

naruto_9w
13th January 2009, 16:43
I dont know about X11, but u can see ARGB window in Trolltech labs --> dojo examples.

Thank your clue very much!

Anyone else can offer some tips for this issue? Thx

naruto_9w
14th January 2009, 07:38
After rebuilding Qt4.5 beta, the sample code works, and it also does in Qt4.4.3.
However the dojo ARGB demo still render black background... :(

codeslicer
14th February 2009, 00:42
On Ubuntu, you might need to have a composite window manager enabled (such as Compiz/Beryl/Metacity Composite).

Otherwise you'll get a black background, and setMask() would be your only best bet.