Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Adding mousePressEvent and mouseMoveEvent to QMediaPlayer?
Forum Updated to NodeBB v4.3 + New Features

Adding mousePressEvent and mouseMoveEvent to QMediaPlayer?

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 3 Posters 706 Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    donquibeats
    wrote on last edited by
    #1

    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?

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi
      Is the QMediaPlayer not a non visual object ? ( seems to be based on QObject)
      and you use a QVideoWidget to show the video ?

      1 Reply Last reply
      2
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #3

        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.

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        2
        • D Offline
          D Offline
          donquibeats
          wrote on last edited by
          #4

          Thanks for pointing out my oversight. I was getting wires crossed between the QVideoWidget and the QMediaPlayer that outputs to it.

          1 Reply Last reply
          1

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved