Пример #1
0
    def pixel_pos_to_range_value(self, pos: QtCore.QPoint):
        opt = QtWidgets.QStyleOptionSlider()
        # Populate opt with the widget's style
        self.initStyleOption(opt)
        groove = self.style().subControlRect(QStyle.CC_Slider, opt,
                                             QStyle.SC_SliderGroove, self)

        if self.orientation() == QtCore.Qt.Horizontal:
            #  sliderLength = handle.width()
            slider_min = groove.x()
            slider_max = groove.right()
        else:
            #  sliderLength = handle.height()
            slider_min = groove.y()
            slider_max = groove.bottom()

        new_pos_scalar = pos.x() if self.orientation(
        ) == QtCore.Qt.Horizontal else pos.y()
        return QStyle.sliderValueFromPosition(
            self.minimum(),  # min
            self.maximum(),  # max
            new_pos_scalar,  # pos (int)
            slider_max - slider_min,  # span (int)
            opt.upsideDown  # upside down (bool)
        )
Пример #2
0
    def mousePressEvent(self, event):
        """
        Update the slider value with a single jump when clicking on the groove.

        @param event:
        @type event:
        """
        pressVal = QStyle.sliderValueFromPosition(
            self.minimum(), self.maximum(), event.x(), self.width(),
            0)  # 0 is for horizontal slider only
        if abs(pressVal - self.value()) > (self.maximum() - self.minimum(
        )) * 20 / self.width():  # handle width should be near 20
            self.setValue(pressVal)
        else:
            super().mousePressEvent(event)
Пример #3
0
 def mousePressEvent(self, event):
     """
     Update the slider value with a single jump when clicking on the groove.
     # min is at left or top. Change upsideDown to True to reverse this behavior.
     @param event:
     @type event:
     """
     pressVal = QStyle.sliderValueFromPosition(self.minimum(),
                                               self.maximum(),
                                               event.x(),
                                               self.width(),
                                               upsideDown=False)
     if abs(pressVal - self.value()) > (self.maximum() - self.minimum(
     )) * 20 / self.width():  # handle width should be near 20
         self.setValue(pressVal)
     else:
         super().mousePressEvent(event)