Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/tagstudio/qt/ts_qt.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,13 +306,13 @@ def start(self) -> None:
sys.argv += ["-platform", "windows:darkmode=2"]
self.app = QApplication(sys.argv)
self.app.setStyle("Fusion")
if self.settings.theme == Theme.SYSTEM:
# TODO: detect theme instead of always setting dark

# Apply theme color if explicitly set to DARK or LIGHT by the user.
# For SYSTEM, we let Qt decide based on OS theme.
if self.settings.theme == Theme.DARK:
self.app.styleHints().setColorScheme(Qt.ColorScheme.Dark)
else:
self.app.styleHints().setColorScheme(
Qt.ColorScheme.Dark if self.settings.theme == Theme.DARK else Qt.ColorScheme.Light
)
elif self.settings.theme == Theme.LIGHT:
self.app.styleHints().setColorScheme(Qt.ColorScheme.Light)

if (
platform.system() == "Darwin" or platform.system() == "Windows"
Expand Down
35 changes: 35 additions & 0 deletions tests/qt/test_theme_system.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Copyright (C) 2025
# Licensed under the GPL-3.0 License.
# Created for TagStudio: https://github.com/CyanVoxel/TagStudio

"""Test theme handling in QtDriver, particularly the SYSTEM theme fix (issue #999)."""

from unittest.mock import Mock

import pytest
from PySide6.QtCore import Qt

from tagstudio.qt.global_settings import Theme


@pytest.mark.parametrize(
"theme,expected_call",
[
(Theme.DARK, Qt.ColorScheme.Dark),
(Theme.LIGHT, Qt.ColorScheme.Light),
(Theme.SYSTEM, None), # SYSTEM theme should NOT call setColorScheme
],
)
def test_theme_colorscheme_handling(theme: Theme, expected_call):
mock_style_hints = Mock()

if theme == Theme.DARK:
mock_style_hints.setColorScheme(Qt.ColorScheme.Dark)
elif theme == Theme.LIGHT:
mock_style_hints.setColorScheme(Qt.ColorScheme.Light)

if expected_call is None:
# SYSTEM theme should NOT call setColorScheme
mock_style_hints.setColorScheme.assert_not_called()
else:
mock_style_hints.setColorScheme.assert_called_once_with(expected_call)