Wobuzz/wobuzz/ui/track_progress_slider.py

34 lines
789 B
Python
Raw Normal View History

#!/usr/bin/python3
from PyQt6.QtCore import Qt
from PyQt6.QtGui import QMouseEvent
from PyQt6.QtWidgets import QSlider
class TrackProgressSlider(QSlider):
2024-12-22 19:42:48 +01:00
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.dragged = False
self.sliderPressed.connect(self.on_press)
self.sliderReleased.connect(self.on_release)
def mousePressEvent(self, event: QMouseEvent):
if event.button() == Qt.MouseButton.LeftButton:
event.accept()
x = event.pos().x()
value = self.maximum() * x // self.width()
self.setValue(value)
return super().mousePressEvent(event)
2024-12-22 19:42:48 +01:00
def on_press(self):
self.dragged = True
def on_release(self):
self.dragged = False