Created
August 15, 2025 17:16
-
-
Save jdboachie/a43dcbdff04e928776102eff672abcd6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from PySide6.QtGui import QGuiApplication, QPalette | |
from PySide6.QtWidgets import QApplication | |
def get_theme_mode() -> str: | |
"""Return 'dark' or 'light' based on the current system/application theme.""" | |
if QApplication.instance() is None: | |
raise RuntimeError("QApplication instance not found. Initialize it first.") | |
palette = QGuiApplication.palette() | |
bg_color = palette.color(QPalette.ColorRole.Window) | |
brightness = ( | |
bg_color.red() * 0.299 + bg_color.green() * 0.587 + bg_color.blue() * 0.114 | |
) | |
return "dark" if brightness < 128 else "light" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment