Unsolved Adding mousePressEvent and mouseMoveEvent to QMediaPlayer?
-
I may be missing something obvious here, but is there a way to add mousePressEvent and mouseMoveEvent triggers to a QMediaPlayer object?
It seems that it, and its parents QMediaObject and QObject, don't support those events. In PyQt5 I'm trying to build a special class that inherits QMediaPlayer and adds some extra behaviours based on mouse clicks and movements, but nothing is happening.
Here's a chunk of my non-working code:
class QMediaPlayerWithGrip(QMediaPlayer): def __init__(self, flags, parent): super(QMediaPlayerWithGrip, self).__init__(flags, parent) self.gripSize = QSize(10, 10) self.resizing = False self.oldPos = None def mouseInGrip(self, mousePos): return ((mousePos.x() > (self.width() - self.gripSize.width())) and (mousePos.y() > (self.height() - self.gripSize.height()))) def mousePressEvent(self, e): print("Mouse press reached") if self.mouseInGrip(e.pos()): self.oldPos = e.pos() self.resizing = True else: self.resizing = False
When the media player is clicked on by the user, I would like the test message "Mouse press reached" to be called, but that message never appears.
Please can somebody tell me if I'm overlooking something obvious, or just messing up in my idea of how inheritance works?
-
Hi
Is the QMediaPlayer not a non visual object ? ( seems to be based on QObject)
and you use a QVideoWidget to show the video ? -
Hi,
QMediaPlayer and its playlist friend are non visual classes.
What you want to do is rather modify the widgets that you'll be using to show/control the media you'll be playing.
-
Thanks for pointing out my oversight. I was getting wires crossed between the QVideoWidget and the QMediaPlayer that outputs to it.