replace ScaledScrollBar with BigScrollBar
step 3 - connect wheel event
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import enum
|
||||
|
||||
from PySide6.QtGui import QWheelEvent
|
||||
from PySide6.QtWidgets import QWidget, QStylePainter, QStyle, QStyleOptionSlider, QSlider, QAbstractSlider
|
||||
from PySide6.QtCore import Qt, QSize, QEvent, QRect, QPoint, Signal
|
||||
|
||||
@@ -46,7 +47,7 @@ class BigScrollBar(QWidget):
|
||||
def paintEvent(self, event):
|
||||
p = QStylePainter(self)
|
||||
o = self.style_options()
|
||||
print(f"style_options: sliderPosition: {o.sliderPosition}")
|
||||
# print(f"style_options: sliderPosition: {o.sliderPosition}")
|
||||
p.drawComplexControl(QStyle.ComplexControl.CC_ScrollBar, o)
|
||||
|
||||
def style_options(self) -> QStyleOptionSlider:
|
||||
@@ -67,8 +68,8 @@ class BigScrollBar(QWidget):
|
||||
o.minimum = self.minimun * t
|
||||
o.maximum = self.maximum * t
|
||||
o.sliderPosition = int(self.value * t)
|
||||
print(f"t={t}")
|
||||
print(f"({self.minimun}, {self.value}, {self.maximum}) -> ({o.minimum},{o.sliderPosition},{o.maximum})")
|
||||
# print(f"t={t}")
|
||||
# print(f"({self.minimun}, {self.value}, {self.maximum}) -> ({o.minimum},{o.sliderPosition},{o.maximum})")
|
||||
|
||||
return o
|
||||
|
||||
@@ -114,7 +115,7 @@ class BigScrollBar(QWidget):
|
||||
|
||||
self.pressedControl = self.style().hitTestComplexControl(QStyle.ComplexControl.CC_ScrollBar, style_options,
|
||||
event.position().toPoint(), self)
|
||||
print(f"pressedControl {self.pressedControl}")
|
||||
# print(f"pressedControl {self.pressedControl}")
|
||||
|
||||
sr: QRect = self.style().subControlRect(QStyle.ComplexControl.CC_ScrollBar, style_options,
|
||||
QStyle.SubControl.SC_ScrollBarSlider, self)
|
||||
@@ -140,7 +141,6 @@ class BigScrollBar(QWidget):
|
||||
# self.repaint(self.style().subControlRect(QStyle.ComplexControl.CC_ScrollBar, style_options, self.pressedControl))
|
||||
|
||||
def activateControl(self, control):
|
||||
action = QAbstractSlider.SliderAction.SliderNoAction
|
||||
match control:
|
||||
case QStyle.SubControl.SC_ScrollBarAddPage:
|
||||
self.scroll_event.emit(self.ScrollEvent.PageDown)
|
||||
@@ -177,6 +177,18 @@ class BigScrollBar(QWidget):
|
||||
# print(f"move to value: {new_position}")
|
||||
self.set_value(new_position)
|
||||
|
||||
def wheelEvent(self, event: QWheelEvent):
|
||||
event.ignore()
|
||||
|
||||
# when using a touchpad we can have simultaneous horizontal and vertical movement
|
||||
horizontal = abs(event.angleDelta().x()) > abs(event.angleDelta().y())
|
||||
if horizontal:
|
||||
return
|
||||
|
||||
scroll_event = self.ScrollEvent.LinesDown if event.angleDelta().y() < 0 else self.ScrollEvent.LinesUp
|
||||
self.scroll_event.emit(scroll_event)
|
||||
|
||||
|
||||
def pixelPosToRangeValue(self, pos: int):
|
||||
opt: QStyleOptionSlider = self.style_options()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user