PDA

View Full Version : Semi-Transparent Background on Widget?



JimDaniel
12th January 2008, 00:25
I'm using my own style, subclassing QWindowsStyle, and I'd like to make the background of a QWidget semi-transparent.

I've been re-drawing my own scrollbars and other widgets, so I'm somewhat familiar with QPainter and its setOpacity() method, but I can't seem to find the correct flag to override the QWidget's background.

What I'd basically like to do is have the main window's background semi-transparent and all the other widgets inside it opaque.

Can someone point me in the right direction?

high_flyer
14th January 2008, 15:53
Do you mean a top level window, or a widget with a parent?
You might find this thread (http://www.qtcentre.org/forum/f-qt-programming-2/t-leaveevent-on-transparent-area-issue-11071.html/?highlight=Transparent)of interest.

aamer4yu
15th January 2008, 06:07
I am not sure how to make background transparent while all other widgets opaque.

But if you want to change background color, you can use QWidget::setPalette( const QPalette &) . If you want to change opacity of the whole widget then QWidget::setWindowOpacity( qreal level )

Hope this helps

Brandybuck
16th January 2008, 19:19
Don't forget setAutoFillBackground(true) if you change the background color in palette. Without that property, your widget will not draw its background.