Skip to content

Commit 11a906a

Browse files
committed
Refactor: removed code which tried enabling tooltips on macOS
1 parent 046bef0 commit 11a906a

File tree

1 file changed

+20
-32
lines changed

1 file changed

+20
-32
lines changed

Orange/widgets/visualize/owscoringsheetviewer.py

Lines changed: 20 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -91,23 +91,6 @@ def handle_item_changed(self, item):
9191
self.main_widget._update_slider_value()
9292

9393

94-
class NonDraggableSlider(QSlider):
95-
"""
96-
A custom slider that ignores mouse events.
97-
98-
It is used instead of disabling the default slider so that the
99-
tooltip will be shown when the mouse is over the slider thumb on macOS.
100-
"""
101-
102-
def mousePressEvent(self, event):
103-
event.ignore()
104-
105-
def mouseMoveEvent(self, event):
106-
event.ignore()
107-
108-
def mouseReleaseEvent(self, event):
109-
event.ignore()
110-
11194

11295
class CustomSliderStyle(QProxyStyle):
11396
"""
@@ -116,21 +99,24 @@ class CustomSliderStyle(QProxyStyle):
11699
It draws a 2px wide black rectangle to replace the default handle.
117100
This is done to suggest to the user that the slider is not interactive.
118101
"""
119-
120102
def drawComplexControl(self, cc, opt, painter, widget=None):
121-
if cc == QStyle.CC_Slider:
122-
opt2 = QStyleOptionSlider(opt)
123-
opt2.subControls &= ~QStyle.SC_SliderHandle
124-
super().drawComplexControl(cc, opt2, painter, widget)
125-
hr = self.subControlRect(cc, opt, QStyle.SC_SliderHandle, widget)
126-
painter.save()
127-
painter.setRenderHint(QPainter.Antialiasing)
128-
painter.fillRect(
129-
QRect(hr.center().x() - 1, hr.y(), 2, hr.height()), Qt.black
130-
)
131-
painter.restore()
132-
else:
133-
super().drawComplexControl(cc, opt, painter, widget)
103+
if cc != QStyle.CC_Slider:
104+
return super().drawComplexControl(cc, opt, painter, widget)
105+
106+
# Make a copy of the style option and remove the handle subcontrol.
107+
slider_opt = QStyleOptionSlider(opt)
108+
slider_opt.subControls &= ~QStyle.SC_SliderHandle
109+
super().drawComplexControl(cc, slider_opt, painter, widget)
110+
111+
# Get the rectangle for the slider handle.
112+
handle_rect = self.subControlRect(cc, opt, QStyle.SC_SliderHandle, widget)
113+
114+
# Draw a simple 2px wide black rectangle as the custom handle.
115+
painter.save()
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()))
119+
painter.restore()
134120

135121

136122
class RiskSlider(QWidget):
@@ -146,12 +132,14 @@ def __init__(self, points, probabilities, parent=None):
146132
self.layout.setContentsMargins(
147133
self.leftMargin, self.topMargin, self.rightMargin, self.bottomMargin
148134
)
135+
self.setMouseTracking(True)
149136

150137
# Setup the labels
151138
self.setup_labels()
152139

153-
self.slider = NonDraggableSlider(Qt.Horizontal, self)
140+
self.slider = QSlider(Qt.Horizontal, self)
154141
self.slider.setStyle(CustomSliderStyle())
142+
self.slider.setEnabled(False)
155143
self.layout.addWidget(self.slider)
156144

157145
self.points = points

0 commit comments

Comments
 (0)