1

In my app there is a button which allows to switch to dark theme. But if a user wants to switch back to the initial theme.

I know that in C++ it can be done like qApp->setPalette(this->style()->standardPalette());.

How can I do it in python?

1 Answers1

0

The qApp is the application instance, which usually is accessed with QtWidgets.QApplication.instance(), or through QtWidgets.qApp (note that they are pointers to the instance, but they'll return different python objects, see qApp versus QApplication.instance() for more information).

QtWidgets.QApplication.instance().setPalette(self.style().standardPalette())

Be aware that this will only restore the palette, but in some systems it's not a good thing to do (from standardPalette() docs:

Note that on systems that support system colors, the style's standard palette is not used. In particular, the Windows Vista and Mac styles do not use the standard palette, but make use of native theme engines. With these styles, you should not set the palette with QApplication::setPalette().

musicamante
  • 41,230
  • 6
  • 33
  • 58