I struggled with this problem myself (PyQt5 5.14) and have figured out how to make macOS' dark mode work with PyQt5. You have to call QApplication.setStyle('style name here')
.
For whatever reason, it seems that any color scheme changes lay inert until "activated" by setStyle()
. (You can see this if you call QApplication.setPalette(palette)
with a custom palette; some colors will change and others won't—until setStyle()
is called, upon which all colors finally change.) I can only speculate that dark mode was detected on app start but not activated.
Why it is that color scheme changes don't apply until setStyle()
is called, I have no idea. I'm guessing it's a bug in PyQt5.
There are two rules to make the setStyle()
trick work:
- You must call
setStyle()
after you've instantiated your QApplication
. This is in addition to the setStyle()
call before instantiating your QApplication
, for a total of two setStyle()
s.
setStyle()
must be called with a string argument. Giving it a QStyle
object does nothing.
So, to have your app sync color schemes with macOS' dark mode:
# Must run before QApplication is instantiated, otherwise certain widget styles will remain unset
PyQt5.QtWidgets.QApplication.setStyle('fusion')
app = YourQApplicationClassHere(sys.argv)
# Must run after QApplication is instantiated, to apply any latent color scheme changes
PyQt5.QtWidgets.QApplication.setStyle('fusion')
Final caveat: If you freeze your app with pyinstaller, not even the setStyle()
trick will work.