-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dark theme #6
Comments
Hi, my code might help you: def show_toast(self, preset, title, text):
preset_mapping = {
"success": (ToastPreset.SUCCESS, ToastPreset.SUCCESS_DARK),
"warning": (ToastPreset.WARNING, ToastPreset.WARNING_DARK),
"error": (ToastPreset.ERROR, ToastPreset.ERROR_DARK),
"info": (ToastPreset.INFORMATION, ToastPreset.INFORMATION_DARK),
}
current_theme = self.model.theme
is_dark_theme = current_theme == "dark"
toast = Toast(self.view)
toast.setDuration(3000)
toast.setTitle(title)
toast.setText(text)
# Select the appropriate preset based on the theme
selected_preset = preset_mapping[preset.lower()][is_dark_theme]
toast.applyPreset(selected_preset)
toast.show() |
Hi, [PySidde6 v6.7.3, OS LinuxMint] QMainWindow has no model.theme. Damage. Your code didn't help me. |
Its normal, model.theme is specific go my app, I created this variable to store the current theme, I didnt meant to just copy paste my code. |
If you're using macOS, then you can check if OS dark mode is set using the func below. If you're using windows or prefer a pypi package, then check out darkdetect. import subprocess
def is_dark_mode() -> bool:
"""
Determines whether the system is currently in dark mode.
The method executes a shell command to read the global AppleInterfaceStyle setting and interprets the output to ascertain if dark mode is enabled.
Returns:
bool: True if dark mode is active, False otherwise.
"""
cmd = 'defaults read -g AppleInterfaceStyle'
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
return bool(p.communicate()[0]) You could pair this with @Crackvignoule code snippet and replace: current_theme = self.model.theme
is_dark_theme = current_theme == "dark" with this:
|
Hi, |
Hi,
can you help me, please?
In main code I'm using for "mainWindow" style as:
QApplication.setStyle(QStyleFactory.create("Fusion"))
How can be automaticaly used Toast Preset *_DARK without set it?
The text was updated successfully, but these errors were encountered: