QPalette is useless after QSS
-
-
ui->centralWidget->setStyleSheet("border:none;"); QColor color = QColorDialog::getColor(color, this); QPalette palette = ui->centralWidget->palette(); palette.setColor(ui->centralWidget->backgroundRole(), color); ui->centralWidget->setPalette(palette);As far as I know, the QSS overwrites palette settings, even if you modify the palette and re-apply it again.
When you need the new palette with color from ColorDialog and "border: none" try to set the stylesheet after palette.ui->centralWidget->setStyleSheet(""); // delete stylesheet QColor color = QColorDialog::getColor(color, this); QPalette palette = ui->centralWidget->palette(); palette.setColor(ui->centralWidget->backgroundRole(), color); ui->centralWidget->setPalette(palette); ui->centralWidget->setStyleSheet("border:none;"); // modify new palette with stylesheetThis works?!
Or what do you mean by "useless"?
-
QSS does not overwrite palette. It just applies a different style (QStylesheetStyle), that may or may not use the palette colors. If you set a stylesheet that hardcodes a color then it won't use the palette.
Still, you can use palette colors in QSS if you want, e.g.
someWidget->setStyleSheet("background-color: palette(background);"); -
As far as I know, the QSS overwrites palette settings, even if you modify the palette and re-apply it again.
When you need the new palette with color from ColorDialog and "border: none" try to set the stylesheet after palette.ui->centralWidget->setStyleSheet(""); // delete stylesheet QColor color = QColorDialog::getColor(color, this); QPalette palette = ui->centralWidget->palette(); palette.setColor(ui->centralWidget->backgroundRole(), color); ui->centralWidget->setPalette(palette); ui->centralWidget->setStyleSheet("border:none;"); // modify new palette with stylesheetThis works?!
Or what do you mean by "useless"?
-
QSS does not overwrite palette. It just applies a different style (QStylesheetStyle), that may or may not use the palette colors. If you set a stylesheet that hardcodes a color then it won't use the palette.
Still, you can use palette colors in QSS if you want, e.g.
someWidget->setStyleSheet("background-color: palette(background);");@Chris-Kawa said in QPalette is useless after QSS:
QSS does not overwrite palette.
Of course it does not change the current palette itself. But it changes the current appearance of the active palette by adding modifications to it. If that makes sense. This is what I mean above.