[Solved] How to override a child QWidget's background colour?
-
Hi all,
I'm trying to make my QLCDNumber change its background colour according to its value.
@
void ParentWidget::updateLcd(int value)
{
QPalette p;if (value > 10) p.setColor(QPalette::Window, QColor("red")); else p.setColor(QPalette::Window, QColor("green")); childLcd->setPalette(p); childLcd->display(value);
}
@This works if the QLCDNumber is created as a top-level widget, but not if it's made a child of ParentWidget -- it seems to be forced to use its parent's palette.
What options do I have?
I've also tried childLcd->setPalette(Qt::red) -- that does work, but it only colours the borders, not the whole background.
-
Ah, apparently I need to call
@
childLcd->setAutoFillBackground(true)
@Works now!