MCPcopy
hub / github.com/PyQt5/PyQt / ClickJumpSlider

Class ClickJumpSlider

QSlider/ClickJumpSlider.py:23–46  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

21
22
23class ClickJumpSlider(QSlider):
24
25 def mousePressEvent(self, event):
26 # 获取上面的拉动块位置
27 option = QStyleOptionSlider()
28 self.initStyleOption(option)
29 rect = self.style().subControlRect(
30 QStyle.CC_Slider, option, QStyle.SC_SliderHandle, self)
31 if rect.contains(event.pos()):
32 # 如果鼠标点击的位置在滑块上则交给Qt自行处理
33 super(ClickJumpSlider, self).mousePressEvent(event)
34 return
35 if self.orientation() == Qt.Horizontal:
36 # 横向,要考虑invertedAppearance是否反向显示的问题
37 self.setValue(self.style().sliderValueFromPosition(
38 self.minimum(), self.maximum(),
39 event.x() if not self.invertedAppearance() else (self.width(
40 ) - event.x()), self.width()))
41 else:
42 # 纵向
43 self.setValue(self.style().sliderValueFromPosition(
44 self.minimum(), self.maximum(),
45 (self.height() - event.y()) if not self.invertedAppearance(
46 ) else event.y(), self.height()))
47
48
49class DemoWindow(QWidget):

Callers 1

__init__Method · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected