Switching DesktopSettingsAware colors for a button
-
If I have a button where it's default colors are set through the Desktop settings, can I switch out two of those colors?
For example:
QPushButton* button = new QPushButton("hello world",this); QPalette pal = button->palette(); pal.setColor(QPalette::Button, QPalette::Base); button->setAutoFillBackground(true); button->setPalette(pal); button->update();In this code I'm setting the button color to QPalette::Base. This works as long as I restart the app whenever settings change, but I'd like to just specify to use the new QPalette::Base during runtime whenever the color changes. ie. switching from light theme to dark theme changes the default QPalette::Base color, but it only updates buttons that don't have their palettes changed.
How can I accomplish this?
Thanks
-
If I have a button where it's default colors are set through the Desktop settings, can I switch out two of those colors?
For example:
QPushButton* button = new QPushButton("hello world",this); QPalette pal = button->palette(); pal.setColor(QPalette::Button, QPalette::Base); button->setAutoFillBackground(true); button->setPalette(pal); button->update();In this code I'm setting the button color to QPalette::Base. This works as long as I restart the app whenever settings change, but I'd like to just specify to use the new QPalette::Base during runtime whenever the color changes. ie. switching from light theme to dark theme changes the default QPalette::Base color, but it only updates buttons that don't have their palettes changed.
How can I accomplish this?
Thanks
@cadol001 try this:
void MainWindow::changeEvent(QEvent *event) { if (event->type() == QEvent::PaletteChange) { QPalette palette = QApplication::style()->standardPalette(); palette.setColor(QPalette::Button, palette.color(QPalette::Base)); button->setPalette(palette); } event->ignore(); }