PDA

View Full Version : Widget Transparency



arunpk
1st June 2012, 09:42
Hi all....
I am also having problem with the Transparency...
I have a parent widget with some background color... And i have two child widgets which i am placing over my parent widget. In this i am placing one child widget over another. And the first child widget which is below the second child should be partially visible means i need my second child widget as semi transparent. I can set the transparency for individual widget. But when i am setting this as a child of another widget i am not able to accomplish that transparency...


Please help me regarding this.. Here i have a dded one image..On that you can see what i really need.....

Thanks in advance... :)
:)

mentalmushroom
1st June 2012, 11:35
I remember I had a similar problem in the past and have not found a qt solution. I've managed to achieve transparency only with win32 code:


#ifdef Q_OS_WIN32
HWND hwnd = (HWND) winId(); // get handle of the widget
LONG styles = GetWindowLong(hwnd, GWL_EXSTYLE);
SetWindowLong(hwnd, GWL_EXSTYLE, styles | WS_EX_TRANSPARENT);
#else


After this transparency should work. Big thanks to anybody who can provide a better way to do this.

Spitfire
6th June 2012, 10:40
I'm not sure if I understood you right, but if you want your widget background to be transparent it's quite simple:


MainWindow::MainWindow( QWidget* p )
:
QMainWindow( p )
{
QWidget* w1 = new QWidget( this );
w1->setFixedSize( 100, 100 );
w1->setStyleSheet( "background: rgba(255, 0, 0, 127);" ); // 50% transparent

QLabel* l = new QLabel( "test test test1", w1 );
l->move( 0, 80 );
l->setStyleSheet( "background: none;" ); // remove inherited background

QWidget* w2 = new QWidget( this );
w2->setFixedSize( 100, 100 );
w2->move( 50, 50 );
w2->setStyleSheet( "background: rgba(0, 255, 0, 127);" ); // 50% transparent

w1->show();
w2->show();
}

This transparency applies only to widget background, so ie button will still be 100% opaque.
Is that what you needed?
7809