PDA

View Full Version : QLCNumber background color



drave
12th December 2009, 12:40
This code (on Qt 4.6)

QPalette Pal = ui->lcdNumber->palette();
Pal.setColor(QPalette::Normal, QPalette::WindowText, Qt::green);
Pal.setColor(QPalette::Normal, QPalette::Window, Qt::black);
ui->lcdNumber->setPalette(Pal);

changes the digits to green OK but has no effect on the background color, which remains light grey.

Why not ?
How can i change the background color ?

thanks

Lykurg
12th December 2009, 13:18
You code for the palette is fine. So try to use QWidget::autoFillBackground.

#include <QtGui>

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

QWidget w;
QLCDNumber lcd(&w);
lcd.setAutoFillBackground(true);// see the different if you comment that line out.

QPalette Pal = lcd.palette();
Pal.setColor(QPalette::Normal, QPalette::WindowText, Qt::green);
Pal.setColor(QPalette::Normal, QPalette::Window, Qt::black);
lcd.setPalette(Pal);


w.show();

return app.exec();
}

drave
12th December 2009, 15:41
that was it

thanks