View Full Version : QLCDNumber with transparent background?

1st October 2008, 22: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);

//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);

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

//Show the widget
return app.exec();

And the result is:


Any ideas how to get rid of the background?



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

20th October 2008, 06: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 :)