Search code examples
qtqt5color-schemeqstyleqpalette

How to set QPalette back to default system palette?


I start my application initially in a dark color theme according to this example.

I would like to make possible for users, to switch back to their current default system color profiles of their operating system (as I start that application without setting QPalette). Is that posssible?


Solution

  • One possible way is just use default settings and parameters:

    void MainWindow::on_pushButton_clicked()
    {
        qApp->setPalette(this->style()->standardPalette());
        qApp->setStyle(QStyleFactory::create("WindowsVista"));
        qApp->setStyleSheet("");
    }
    

    But this way has some limitation: we need some QWidget for setting palette, in my way I use this poiter to QMainWindow, however it is not so serious problem i think.