PDA

View Full Version : transparent widget



hijinks
19th February 2006, 02:34
I have a little game I'm making in qt 4.1. Right now I'm doing this part while on a windows XP machine. I have a mainwindow which basicall gets created like this



GUI::GUI() {
// setting the max/min size
setMinimumSize(350, 450);
setMaximumSize(350, 450);

// filling the background with white
//setAutoFillBackground(true);
QPalette palette;
palette.setColor(QPalette::Background, Qt::white);
setPalette(palette);


Now when i start a new game I want to overlay like a black widget that has like a 50% transparency so you can still see the little gameboard and such. I am having no such luck getting another widget to be transparent over my mainwindow

Here is my latest attempt at trying to get it to work



QWidget *blackBG = new QWidget(this);
blackBG->setGeometry(0,0,350,450);
blackBG->setAutoFillBackground(true);
blackBG->setPalette(QPalette(QPalette::Background, Qt::black));
blackBG->setWindowOpacity(.5);
blackBG->show();



any help? thanks!

axeljaeger
19th February 2006, 11:47
SetWindowOpacity only works for topLevelWindows as slightly mentioned in the docs:

http://doc.trolltech.com/4.1/qwidget.html#windowOpacity-prop

They use the term window instead of widget.

You will have to draw the semi transparent layer in the paintEvent of your widget beneath the layer.

Mike
20th February 2006, 10:43
Scott Collins talked about this in his blog. Did you try this?

http://scottcollins.net/blog/2005/10/transparent-backgrounds-in-qt.html