|
15 | 15 | QStyleOptionSlider, |
16 | 16 | ) |
17 | 17 | from AnyQt.QtCore import Qt, QRect |
18 | | -from AnyQt.QtGui import QPainter, QFontMetrics |
| 18 | +from AnyQt.QtGui import QPainter, QFontMetrics, QPalette |
19 | 19 |
|
20 | 20 | from Orange.widgets import gui |
21 | 21 | from Orange.widgets.settings import ContextSetting |
@@ -91,31 +91,37 @@ def handle_item_changed(self, item): |
91 | 91 | self.main_widget._update_slider_value() |
92 | 92 |
|
93 | 93 |
|
94 | | - |
95 | 94 | class CustomSliderStyle(QProxyStyle): |
96 | 95 | """ |
97 | 96 | A custom slider handle style. |
98 | | - |
| 97 | +
|
99 | 98 | It draws a 2px wide black rectangle to replace the default handle. |
100 | 99 | This is done to suggest to the user that the slider is not interactive. |
101 | 100 | """ |
| 101 | + |
102 | 102 | def drawComplexControl(self, cc, opt, painter, widget=None): |
103 | 103 | if cc != QStyle.CC_Slider: |
104 | 104 | return super().drawComplexControl(cc, opt, painter, widget) |
105 | | - |
| 105 | + |
106 | 106 | # Make a copy of the style option and remove the handle subcontrol. |
107 | 107 | slider_opt = QStyleOptionSlider(opt) |
108 | 108 | slider_opt.subControls &= ~QStyle.SC_SliderHandle |
109 | 109 | super().drawComplexControl(cc, slider_opt, painter, widget) |
110 | 110 |
|
111 | 111 | # Get the rectangle for the slider handle. |
112 | 112 | handle_rect = self.subControlRect(cc, opt, QStyle.SC_SliderHandle, widget) |
113 | | - |
| 113 | + |
114 | 114 | # Draw a simple 2px wide black rectangle as the custom handle. |
115 | 115 | painter.save() |
116 | 116 | 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 | + ) |
119 | 125 | painter.restore() |
120 | 126 |
|
121 | 127 |
|
|
0 commit comments