6

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?

Ralf Wickum
  • 2,850
  • 9
  • 55
  • 103

1 Answers1

12

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.

t3ft3l--i
  • 1,372
  • 1
  • 14
  • 21
  • 3
    You can use qApp->setPalette(QApplication::style()->standardPalette()); to avoid the need for "this" pointer. – RandomGuy Feb 07 '18 at 14:44
  • or just `qApp->setStyle(qApp->style()->standardPalette());`, the, in my eyes, most intuitive one – IceFire Jan 30 '21 at 13:40