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
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