PDA

View Full Version : Transparent Widgets and alpha blending



idoroth
11th October 2011, 14:52
Hi,
In my application my main Widget - 'centralWidget' is the child of the main window class, that is its parent isn't a widget but rather the main class of the application.
I am trying to set 'centralWidget' to be transparent, that is rgba = 0,0,0,0 (alpha blending).
here is what I have tried:

centralWidget->setStyleSheet("background: transparent");

or
QPalette pal = ui->centralWidget->palette();
QColor BGcolor(0,0,0,0);
pal.setColor(ui->centralWidget->backgroundRole(), BGcolor);
centralWidget->setPalette(pal);
centralWidget->setAttribute(Qt::WA_NoSystemBackground);


both make the children of 'centralWidget' transparent but do nothing to 'centralWidget'.

any leads or ideas will be very appreciated.
thanks,
Ido.

john_god
11th October 2011, 16:13
You have to set attributes in the constructor of your widget


setAttribute(Qt::WA_TranslucentBackground,true);
setWindowFlags(Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint );
setWindowOpacity(0.5);

bool t=testAttribute ( Qt::WA_TranslucentBackground);
qDebug()<<t;

The Qt::WA_TranslucentBackground is mandatory, the other flags I dont remember if they are, check the Qt documentation. Also, in linux, you have to enable transparency in your X-window system. In my machine, without compiz enabled, it doenst work, but with compiz works fine.

idoroth
16th October 2011, 09:02
John, my good man. right on the nail's head.
Great help.
Thanks for you time and effort.
Ido.