Skip to content

Commit d12c8cd

Browse files
committed
Improve slider handle styling for dark mode and aesthetics
1 parent 11a906a commit d12c8cd

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

Orange/widgets/visualize/owscoringsheetviewer.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
QStyleOptionSlider,
1616
)
1717
from AnyQt.QtCore import Qt, QRect
18-
from AnyQt.QtGui import QPainter, QFontMetrics
18+
from AnyQt.QtGui import QPainter, QFontMetrics, QPalette
1919

2020
from Orange.widgets import gui
2121
from Orange.widgets.settings import ContextSetting
@@ -91,31 +91,37 @@ def handle_item_changed(self, item):
9191
self.main_widget._update_slider_value()
9292

9393

94-
9594
class CustomSliderStyle(QProxyStyle):
9695
"""
9796
A custom slider handle style.
98-
97+
9998
It draws a 2px wide black rectangle to replace the default handle.
10099
This is done to suggest to the user that the slider is not interactive.
101100
"""
101+
102102
def drawComplexControl(self, cc, opt, painter, widget=None):
103103
if cc != QStyle.CC_Slider:
104104
return super().drawComplexControl(cc, opt, painter, widget)
105-
105+
106106
# Make a copy of the style option and remove the handle subcontrol.
107107
slider_opt = QStyleOptionSlider(opt)
108108
slider_opt.subControls &= ~QStyle.SC_SliderHandle
109109
super().drawComplexControl(cc, slider_opt, painter, widget)
110110

111111
# Get the rectangle for the slider handle.
112112
handle_rect = self.subControlRect(cc, opt, QStyle.SC_SliderHandle, widget)
113-
113+
114114
# Draw a simple 2px wide black rectangle as the custom handle.
115115
painter.save()
116116
painter.setPen(Qt.NoPen)
117-
painter.setBrush(Qt.black)
118-
painter.drawRect(QRect(handle_rect.center().x() - 1, handle_rect.y(), 4, handle_rect.height()))
117+
painter.setBrush(QPalette().color(QPalette.WindowText))
118+
painter.drawRoundedRect(
119+
QRect(
120+
handle_rect.center().x() - 1, handle_rect.y(), 3, handle_rect.height()
121+
),
122+
3,
123+
3,
124+
)
119125
painter.restore()
120126

121127

0 commit comments

Comments
 (0)