Skip to content

Commit

Permalink
Refactor: removed code which tried enabling tooltips on macOS
Browse files Browse the repository at this point in the history
  • Loading branch information
ZanMervic committed Feb 11, 2025
1 parent 046bef0 commit 11a906a
Showing 1 changed file with 20 additions and 32 deletions.
52 changes: 20 additions & 32 deletions Orange/widgets/visualize/owscoringsheetviewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,23 +91,6 @@ def handle_item_changed(self, item):
self.main_widget._update_slider_value()


class NonDraggableSlider(QSlider):
"""
A custom slider that ignores mouse events.
It is used instead of disabling the default slider so that the
tooltip will be shown when the mouse is over the slider thumb on macOS.
"""

def mousePressEvent(self, event):
event.ignore()

def mouseMoveEvent(self, event):
event.ignore()

def mouseReleaseEvent(self, event):
event.ignore()


class CustomSliderStyle(QProxyStyle):
"""
Expand All @@ -116,21 +99,24 @@ class CustomSliderStyle(QProxyStyle):
It draws a 2px wide black rectangle to replace the default handle.
This is done to suggest to the user that the slider is not interactive.
"""

def drawComplexControl(self, cc, opt, painter, widget=None):
if cc == QStyle.CC_Slider:
opt2 = QStyleOptionSlider(opt)
opt2.subControls &= ~QStyle.SC_SliderHandle
super().drawComplexControl(cc, opt2, painter, widget)
hr = self.subControlRect(cc, opt, QStyle.SC_SliderHandle, widget)
painter.save()
painter.setRenderHint(QPainter.Antialiasing)
painter.fillRect(
QRect(hr.center().x() - 1, hr.y(), 2, hr.height()), Qt.black
)
painter.restore()
else:
super().drawComplexControl(cc, opt, painter, widget)
if cc != QStyle.CC_Slider:
return super().drawComplexControl(cc, opt, painter, widget)

# Make a copy of the style option and remove the handle subcontrol.
slider_opt = QStyleOptionSlider(opt)
slider_opt.subControls &= ~QStyle.SC_SliderHandle

Check warning on line 108 in Orange/widgets/visualize/owscoringsheetviewer.py

View check run for this annotation

Codecov / codecov/patch

Orange/widgets/visualize/owscoringsheetviewer.py#L107-L108

Added lines #L107 - L108 were not covered by tests
super().drawComplexControl(cc, slider_opt, painter, widget)

# Get the rectangle for the slider handle.
handle_rect = self.subControlRect(cc, opt, QStyle.SC_SliderHandle, widget)

Check warning on line 113 in Orange/widgets/visualize/owscoringsheetviewer.py

View check run for this annotation

Codecov / codecov/patch

Orange/widgets/visualize/owscoringsheetviewer.py#L111-L113

Added lines #L111 - L113 were not covered by tests
# Draw a simple 2px wide black rectangle as the custom handle.
painter.save()
painter.setPen(Qt.NoPen)

Check warning on line 116 in Orange/widgets/visualize/owscoringsheetviewer.py

View check run for this annotation

Codecov / codecov/patch

Orange/widgets/visualize/owscoringsheetviewer.py#L116

Added line #L116 was not covered by tests
painter.setBrush(Qt.black)
painter.drawRect(QRect(handle_rect.center().x() - 1, handle_rect.y(), 4, handle_rect.height()))
painter.restore()


Check warning on line 121 in Orange/widgets/visualize/owscoringsheetviewer.py

View check run for this annotation

Codecov / codecov/patch

Orange/widgets/visualize/owscoringsheetviewer.py#L119-L121

Added lines #L119 - L121 were not covered by tests
class RiskSlider(QWidget):
Expand All @@ -146,12 +132,14 @@ def __init__(self, points, probabilities, parent=None):
self.layout.setContentsMargins(
self.leftMargin, self.topMargin, self.rightMargin, self.bottomMargin
)
self.setMouseTracking(True)

# Setup the labels
self.setup_labels()

self.slider = NonDraggableSlider(Qt.Horizontal, self)
self.slider = QSlider(Qt.Horizontal, self)
self.slider.setStyle(CustomSliderStyle())
self.slider.setEnabled(False)
self.layout.addWidget(self.slider)

self.points = points
Expand Down

0 comments on commit 11a906a

Please sign in to comment.