Skip to content

Commit

Permalink
fix(ui): restore Windows accent color on PySide 6.8.0.1 (Fix #668) (#755
Browse files Browse the repository at this point in the history
)

* fix(ui): use the new correct(ish) accent color role for Windows

* ui: boost Windows `AlternateBase` lightness
  • Loading branch information
CyanVoxel authored Jan 31, 2025
1 parent 82edbee commit e0d21c1
Showing 1 changed file with 43 additions and 10 deletions.
53 changes: 43 additions & 10 deletions tagstudio/src/qt/widgets/thumb_button.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
# Created for TagStudio: https://github.com/CyanVoxel/TagStudio


import sys

from PySide6 import QtCore
from PySide6.QtCore import QEvent
from PySide6.QtGui import (
Expand All @@ -25,11 +27,27 @@ def __init__(self, parent: QWidget, thumb_size: tuple[int, int]) -> None: # noq
self.hovered = False
self.selected = False

self.select_color: QColor = QPalette.color(
self.palette(),
QPalette.ColorGroup.Active,
QPalette.ColorRole.Accent,
)
# NOTE: As of PySide 6.8.0.1, the QPalette.ColorRole.Accent role no longer works on Windows.
# The QPalette.ColorRole.AlternateBase does for some reason, but not on macOS.
self.select_color: QColor
if sys.platform == "win32":
self.select_color = QPalette.color(
self.palette(),
QPalette.ColorGroup.Active,
QPalette.ColorRole.AlternateBase,
)
self.select_color.setHsl(
self.select_color.hslHue(),
self.select_color.hslSaturation(),
max(self.select_color.lightness(), 100),
255,
)
else:
self.select_color = QPalette.color(
self.palette(),
QPalette.ColorGroup.Active,
QPalette.ColorRole.Accent,
)

self.select_color_faded: QColor = QColor(self.select_color)
self.select_color_faded.setHsl(
Expand All @@ -39,11 +57,26 @@ def __init__(self, parent: QWidget, thumb_size: tuple[int, int]) -> None: # noq
127,
)

self.hover_color: QColor = QPalette.color(
self.palette(),
QPalette.ColorGroup.Active,
QPalette.ColorRole.Accent,
)
self.hover_color: QColor
if sys.platform == "win32":
self.hover_color = QPalette.color(
self.palette(),
QPalette.ColorGroup.Active,
QPalette.ColorRole.AlternateBase,
)
self.hover_color.setHsl(
self.hover_color.hslHue(),
self.hover_color.hslSaturation(),
max(self.hover_color.lightness(), 100),
255,
)
else:
self.hover_color = QPalette.color(
self.palette(),
QPalette.ColorGroup.Active,
QPalette.ColorRole.Accent,
)

self.hover_color.setHsl(
self.hover_color.hslHue(),
self.hover_color.hslSaturation(),
Expand Down

0 comments on commit e0d21c1

Please sign in to comment.