Results 1 to 10 of 10

Thread: [Qt Widget + libvlc] catching mouse events

  1. #1
    Join Date
    Feb 2011
    Posts
    354
    Thanks
    17
    Thanked 27 Times in 24 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Windows

    Default [Qt Widget + libvlc] catching mouse events

    Hello. I am using libvlc in my application to play video that is displayed in QFrame window. I'd like to show a pop-up menu when a user does a right click with mouse. My problem is I can't catch the event, because VLC "eats" it. I know I can disable VLC events handling via libvlc_video_set_mouse_input, but then DVD menu won't work. I've tried to use event filters without any success. Not really a qt problem, but maybe there are some means to achieve what I am talking about or, perhaps, somebody here found a solution or workaround for that.

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: [Qt Widget + libvlc] catching mouse events

    How did you try to catch the mouse event?
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. #3
    Join Date
    Feb 2011
    Posts
    354
    Thanks
    17
    Thanked 27 Times in 24 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Windows

    Default Re: [Qt Widget + libvlc] catching mouse events

    I've tried to install the event filter:
    Qt Code:
    1. // i install it in the MainWindow's constructor
    2. playerWnd->installEventFilter(this); // this = MainWindow that contains playerWnd (QFrame)
    3.  
    4. // the event filter function:
    5. bool MainWindow::eventFilter(QObject *watched, QEvent *event)
    6. {
    7. if (watched == playbar && event->type() == QEvent::MouseButtonPress)
    8. {
    9. QMouseEvent *mouseEvent = static_cast<QMouseEvent*>(event);
    10.  
    11. if (mouseEvent->button() == Qt::LeftButton)
    12. QMessageBox::warning(this, "title", "this is VLC popup menu, don't you believe?");
    13. }
    14.  
    15. return QMainWindow::eventFilter(watched, event);
    16. }
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: [Qt Widget + libvlc] catching mouse events

    The first thing I would do is to make sure you are not chasing your tail.
    Put another empty QFrame on the main window and see if you can catch its mouse event (with the same code).
    If you do, then indeed this has to do with your usage of vlc - in that case, I'd look in to vlc documentation about (mouse) events propagation to host windows.
    If you don't we can have a further look what is wrong in your Qt code.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  5. #5
    Join Date
    Feb 2011
    Posts
    354
    Thanks
    17
    Thanked 27 Times in 24 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Windows

    Default Re: [Qt Widget + libvlc] catching mouse events

    Well, i am sure this is a vlc issue. I asked it here only in a hope somebody knows the solution (preferably via qt means, because my app is written in qt).

  6. #6
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: [Qt Widget + libvlc] catching mouse events

    Well, i am sure this is a vlc issue.
    How so?
    If you explain why you are sure about it, it might help get and idea for a solution.

    EDIT:
    I just noticed this:
    I'd like to show a pop-up menu when a user does a right click with mouse.
    and
    Qt Code:
    1. if (mouseEvent->button() == Qt::LeftButton) //LeftButton!!
    2. QMessageBox::warning(this, "title", "this is VLC popup menu, don't you believe?");
    To copy to clipboard, switch view to plain text mode 
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  7. #7
    Join Date
    Feb 2011
    Posts
    354
    Thanks
    17
    Thanked 27 Times in 24 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Windows

    Default Re: [Qt Widget + libvlc] catching mouse events

    I can handle mouse events without any problems when I don't use vlc. When I use libvlc to play video inside the widget, it uses those events for its own needs (e.g. DVD menu), but I'd like to do some custom processing of that messages before they are handled by vlc. The only way I found to solve this is to use windows global hook, but it is very inconvenient, complex approach, affects the overall system performance, moreover, it is platform-dependent.

    There are other links about the same problem:
    http://trac.videolan.org/vlc/ticket/2816
    http://forum.videolan.org/viewtopic.php?f=32&t=84456
    http://forum.videolan.org/viewtopic.php?f=32&t=79315

  8. #8
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: [Qt Widget + libvlc] catching mouse events

    In one of the links you posted they wrote:
    it's best to disable LibVLC keyboard and mouse events with libvlc_set_key_input(false) and libvlc_set_mouse_input(false). Then the X server will pass the events to the parent widget that VLC is drawing to, which belonds to your application.
    Which is what I meant with:
    If you do, then indeed this has to do with your usage of vlc - in that case, I'd look in to vlc documentation about (mouse) events propagation to host windows.
    Did you try that approach?
    There was another interesting idea in that thread - set the QFrame to 'disabled' which will force the mouse events to propagate to your main window.
    But the first approach seems better to me.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  9. #9
    Join Date
    Feb 2011
    Posts
    354
    Thanks
    17
    Thanked 27 Times in 24 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Windows

    Default Re: [Qt Widget + libvlc] catching mouse events

    As far as I know, there are no such functions in libvlc as libvlc_set_key_input or libvlc_set_mouse_input. If you meant libvlc_video_set_key_input and libvlc_video_set_mouse_input, yes, I've tried it as I wrote in the original post. These functions control whether vlc should handle mouse events, but I don't want to disable it, because then DVD menu won't work. I just need to add some custom processing, so I could show a menu on right click.

    Regarding the second idea, maybe I misunderstand something, but it seems like disabling QFrame doesn't affect anything when video is played inside the frame and mouse handling is enabled for libvlc.

  10. #10
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: [Qt Widget + libvlc] catching mouse events

    As far as I know, there are no such functions in libvlc as libvlc_set_key_input or libvlc_set_mouse_input. If you meant libvlc_video_set_key_input and libvlc_video_set_mouse_input, yes, I've tried it as I wrote in the original post.
    I didn't mean either (as I am not a vlc user and don't know its API) - I just quoted the post from the link you posted - its probably a version issue, and I guess the methods you are using are the correct ones.

    Regarding the second idea, maybe I misunderstand something, but it seems like disabling QFrame doesn't affect anything when video is played inside the frame and mouse handling is enabled for libvlc.
    The idea was that if the QFrame is disabled, so must all its children be - thus they will not get any mouse events.
    But even if it would work - you still have the problem using the regular vlc DVD menu which you do want.

    It seems to me this is strictly VLC issue - as you stated - and specifically - about how vlc propagates (or not) events to the host windows.
    You might have more luck in VLC specific forums.

    Good luck!
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

Similar Threads

  1. Catching Mouse Events on Top-Level Window
    By andyp in forum Qt Programming
    Replies: 6
    Last Post: 8th September 2009, 10:26
  2. Determining when mouse over widget without events
    By Kimmo in forum Qt Programming
    Replies: 2
    Last Post: 7th November 2007, 10:48
  3. Mouse Events in a widget
    By Rayven in forum Qt Programming
    Replies: 2
    Last Post: 5th May 2006, 14:07
  4. Catching X Events
    By nupul in forum Qt Programming
    Replies: 3
    Last Post: 16th April 2006, 12:43
  5. Forwarding mouse events to another widget.
    By yogeshm02 in forum Qt Programming
    Replies: 8
    Last Post: 28th February 2006, 13:25

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.