PDA

View Full Version : QLCDNumber with transparent background?



PolyVox
1st October 2008, 21:05
Hi Guys, I would like to display a QLCDWidget with no background. Eventually I will make it frameless as well (so it's just a floating number), but I haven't been able to get rid of the background yet. The background show up black, rather than being absent:


int main(int argc, char *argv[])
{
QApplication app(argc, argv);

//Set up the QLCDNumber
QLCDNumber* lcdNumber = new QLCDNumber(3,0);
lcdNumber->display(123);
lcdNumber->setSegmentStyle(QLCDNumber::Flat);

//A palette with crazy colors to help see what's going on
//Setting the background to Qt::transpatent here didn't seem to help
QPalette palette = lcdNumber->palette();
palette.setColor(QPalette::Active, QPalette::WindowText, Qt::green);
palette.setColor(QPalette::Active, QPalette::Window, Qt::red);
palette.setColor(QPalette::Inactive, QPalette::WindowText, Qt::blue);
palette.setColor(QPalette::Inactive, QPalette::Window, Qt::yellow);
lcdNumber->setPalette(palette);

//The following code should supress the background?
//Also tried setAutoFillBackground instead of Qt::WA_OpaquePaintEvent
//lcdNumber->setAutoFillBackground(true);
lcdNumber->setAttribute(Qt::WA_OpaquePaintEvent, true);
lcdNumber->setAttribute(Qt::WA_NoBackground, true);
lcdNumber->setAttribute(Qt::WA_NoSystemBackground, true);

//Show the widget
lcdNumber->show();
return app.exec();
}

And the result is:

http://www.david-williams.info/linked_from_web/qt/qlcdnumber-problem.png

Any ideas how to get rid of the background?

Thanks!

David

duduqq
19th October 2008, 07:27
Maybe you must open the xrender

aamer4yu
20th October 2008, 05:34
I dont think you can achieve it directly in windows.
You may try this -
draw the numbers on a pixmap, create a mask from the pixmap and set it on the widget. In this way you might get only numbers displayed.

Look for the shaped clock example in Qt demo how to use masks on widgets :)