I want to detect if a user drags a QSlider handle all the way to the end.
I created a video player that displays the video frames in a QLabel object. A horizontal QSlider object tracks the video position and can also be dragged to position the video. I want the video player to do one thing if the video plays all the way to the end and do something else if the user drags the slider all the way to the end.
I tried detecting if the mouse button is pressed when the slider reaches the end, but have not been able to get that to work in the script below. Is there some other way to determine if the end of the slider is reached when the user drags the slider (mouse button pressed) versus when the video plays to the end by itself (mouse button not pressed)?
from PyQt5 import QtCore, QtWidgets
import sys
class MainWindow(QtWidgets.QMainWindow):
def __init__(self, parent=None):
super().__init__(parent)
central_widget = QtWidgets.QWidget()
self.setCentralWidget(central_widget)
self.label = QtWidgets.QLabel()
self.label.setStyleSheet("border: 1px solid black")
self.slider = QtWidgets.QSlider()
self.slider.setOrientation(QtCore.Qt.Horizontal)
lay = QtWidgets.QVBoxLayout(central_widget)
#lay.addWidget(self.label)
lay.addWidget(self.slider)
self.resize(640, 480)
def mousePressEvent(self, event):
super().mousePressEvent(event)
self.label.setText('Pressed')
def mouseReleaseEvent(self, event):
super().mouseReleaseEvent(event)
self.label.setText('Released')
def sliderPressed(self, event):
super().sliderPressed(event)
self.label.setText('Pressed')
def sliderReleased(self, event):
super().sliderReleased(event)
self.label.setText('Released')
if __name__ == "__main__":
app = QtWidgets.QApplication(sys.argv)
w = MainWindow()
w.show()
sys.exit(app.exec_())