Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Trying to make a dark- lightmode switcher

im trying to make a Button which switches between light and darkmode. Switching to darkmode is pretty easy, but switching to lightmode again is a bit complicated
I try to switch to the default Palette but idk how it really works..
This is the function:

    def modeSwitch(self):
        if self.dark_mode:
            self.dark_mode = False
            QApplication.setPalette("")
        else:   
            self.dark_mode = True
            dark_palette = QPalette()
            dark_palette.setColor(QPalette.Window, QColor(35, 35, 35))
            dark_palette.setColor(QPalette.WindowText, Qt.white)
            dark_palette.setColor(QPalette.Base, QColor(35, 35, 35))
            dark_palette.setColor(QPalette.AlternateBase, QColor(35, 35, 35))
            dark_palette.setColor(QPalette.ToolTipBase, QColor(35, 35, 35))
            dark_palette.setColor(QPalette.ToolTipText, Qt.white)
            dark_palette.setColor(QPalette.Text, Qt.white)
            dark_palette.setColor(QPalette.Button, QColor(35, 35, 35))
            dark_palette.setColor(QPalette.ButtonText, Qt.white)
            dark_palette.setColor(QPalette.BrightText, Qt.red)
            dark_palette.setColor(QPalette.Link, QColor(35, 35, 35))
            dark_palette.setColor(QPalette.Highlight, QColor(35, 35, 35))
            dark_palette.setColor(QPalette.HighlightedText, QColor(97, 97, 97))
            dark_palette.setColor(QPalette.Active, QPalette.Button, QColor(35, 35, 35))
            dark_palette.setColor(QPalette.Disabled, QPalette.ButtonText, Qt.darkGray)
            dark_palette.setColor(QPalette.Disabled, QPalette.WindowText, Qt.darkGray)
            dark_palette.setColor(QPalette.Disabled, QPalette.Text, Qt.darkGray)
            dark_palette.setColor(QPalette.Disabled, QPalette.Light, QColor(35, 35, 35))
            QApplication.setPalette(dark_palette)

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

To reset the palette back to the system default, you can call:

QApplication.setPalette(QApplication.style().standardPalette())

This fetches the palette from the current style, which will be the system default.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading