PDA

View Full Version : Partial window transparency



bunjee
10th March 2009, 13:24
Hey folks,

Is it possible for a main QWidget or a QMainWidget to be partially transparent in Qt 4.5 ?

koral
10th March 2009, 15:53
Of course it is! Just set this flag (introduced in 4.5, it was trickier before):

topLevelWidget->setAttribute( Qt::WA_TranslucentBackground, true );

and if you can't see behind your window, just use some non-opaque color, like:

QPalette pal;
pal.setBrush( QPalette::Window, QColor(255, 0, 0, 64) );
topLevelWidget->setPalette(pal);
topLevelWidget->setAutoFillBackground(true); // maybe it's the default!

and if you still have troubles, *paint with a glass painting* on your paintEvent(...) ;-), like:

QPainter p( this );
p.fillRect( rect(), Qt::transparent /*QColor(0, 0, 0, 0)*/ );

Note that on X11 your window will be transparent only with compositing active (compiz, kwin4 with effects, ...etc).