I want a QLabel whose parent has a custom QPalette to have the default palette. What's the best way of doing that?
I thought it would just be something like:
label->setPalette(p);
QPalette p;
label->setPalette(p);
To copy to clipboard, switch view to plain text mode
But that doesn't work, label still inherits its parent's palette. Whether that's done before or after its parent's palette has changed from the default.
I found that
label->setPalette(p);
QPalette p;
QColor c;
c = p.color(QPalette::WindowText);
p.setColor(QPalette::WindowText, c);
label->setPalette(p);
To copy to clipboard, switch view to plain text mode
works. The label than gets the default QPalette::WindowText colour rather than its parent's. But that just confuses me further as I cannot see why the second code snippet would work but not the first.
So two questions. What is the best way to set a child widget's palette to the default if its parent uses a different palette. And why does the second code snippet have a different result than the first when they look like they should do the same thing?
Bookmarks