How to disable macOS dark mode for pyside2 / pyqt scripts?

594 views Asked by At

I've got several scripts with small GUIs written with PySide2. A lot of them have parts with individual widget stylesheets and are not readable in macOS dark mode.

So instead of updating the GUIs I'd like to disable dark mode completely for certain scripts.

I know about the Info.plist setting, but this is not applicable for single python scripts, only for frozen and bundled applications. Also I found no way to use the light palette by default. Any hints?

1

There are 1 answers

2
Martí Climent On

Well, you could define your own stylesheet in your QMainWindow Stylesheet:

stylesheet = """
    * {
        color: #000000;
        background-color: #FFFFFF; 
    }
    QLabel {
        color: #000000;
        background-color: #FFFFFF; 
    }
    QPushButton {
        color: #000000;
        background-color: #FFFFFF; 
    }

  etc.

"""
window.setStyleSheet(stylesheet)

and if you want this to happen only on macOS:

from sys import platform as _platform
if(_platform=='darwin'):
    window.setStyleSheet(stylesheet)