Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
[Solved] How to override a child QWidget's background colour?
I'm trying to make my QLCDNumber change its background colour according to its value.
void ParentWidget::updateLcd(int value)
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