Last active
December 8, 2018 11:08
-
-
Save QuantumCD/9863860 to your computer and use it in GitHub Desktop.
Skeleton to switch a QMainWindow's palette, as well as all the child widgets' palette (can be used for dynamic theming)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The button clicked events can be replaced with any slots, and/or you can define the | |
// switchPalette() to be a slot to use with QObject::connect() | |
// Dark Palette push button | |
void MainWindow::on_switchToDarkTheme_clicked() | |
{ | |
this->switchPalette(darkPalette); | |
} | |
// Light palette push button | |
void MainWindow::on_switchToLightTheme_clicked() | |
{ | |
this->switchPalette(lightPalette); | |
} | |
void MainWindow::switchPalette(const QPalette& palette) | |
{ | |
this->setPalette(palette); | |
QList<QWidget*> widgets = this->findChildren<QWidget*>(); | |
foreach (QWidget* w, widgets) | |
{ | |
w->setPalette(palette); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment