From 8e3bf5f02f812e6923181440485b72ca1190769a Mon Sep 17 00:00:00 2001 From: YektaY Date: Thu, 23 May 2024 12:14:15 -0700 Subject: [PATCH] fixed issue with vertical slider --- pydm/widgets/slider.py | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/pydm/widgets/slider.py b/pydm/widgets/slider.py index 9683aefc3..db67101a4 100644 --- a/pydm/widgets/slider.py +++ b/pydm/widgets/slider.py @@ -38,19 +38,29 @@ def mousePressEvent(self, event): handle_pos = self.value() * (self.width() - self.handleWidth()) / (self.maximum() - self.minimum()) click_pos = event.pos().x() else: - handle_pos = self.value() * (self.height() - self.handleWidth()) / (self.maximum() - self.minimum()) + handle_pos = ( + (self.maximum() - self.value()) + * (self.height() - self.handleWidth()) + / (self.maximum() - self.minimum()) + ) click_pos = event.pos().y() - if click_pos > handle_pos: - self.setValue(self.value() + self.singleStep()) + if self.orientation() == Qt.Horizontal: + if click_pos > handle_pos + self.handleWidth() / 2: + self.setValue(self.value() + self.singleStep()) + else: + self.setValue(self.value() - self.singleStep()) else: - self.setValue(self.value() - self.singleStep()) + if click_pos < handle_pos + self.handleWidth() / 2: + self.setValue(self.value() + self.singleStep()) + else: + self.setValue(self.value() - self.singleStep()) def handleWidth(self): if self.orientation() == Qt.Horizontal: - return self.style().pixelMetric(self.style().PM_SliderThickness, None, self) - else: return self.style().pixelMetric(self.style().PM_SliderLength, None, self) + else: + return self.style().pixelMetric(self.style().PM_SliderThickness, None, self) class PyDMSlider(QFrame, TextFormatter, PyDMWritableWidget, new_properties=_step_size_properties):