PDA

View Full Version : [Qt Widget + libvlc] catching mouse events



mentalmushroom
5th March 2012, 13:51
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.

high_flyer
6th March 2012, 10:12
How did you try to catch the mouse event?

mentalmushroom
6th March 2012, 10:22
I've tried to install the event filter:


// i install it in the MainWindow's constructor
playerWnd->installEventFilter(this); // this = MainWindow that contains playerWnd (QFrame)

// the event filter function:
bool MainWindow::eventFilter(QObject *watched, QEvent *event)
{
if (watched == playbar && event->type() == QEvent::MouseButtonPress)
{
QMouseEvent *mouseEvent = static_cast<QMouseEvent*>(event);

if (mouseEvent->button() == Qt::LeftButton)
QMessageBox::warning(this, "title", "this is VLC popup menu, don't you believe?");
}

return QMainWindow::eventFilter(watched, event);
}

high_flyer
6th March 2012, 10:32
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.

mentalmushroom
6th March 2012, 10:42
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).

high_flyer
6th March 2012, 11:11
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


if (mouseEvent->button() == Qt::LeftButton) //LeftButton!!
QMessageBox::warning(this, "title", "this is VLC popup menu, don't you believe?");

mentalmushroom
6th March 2012, 11:24
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

high_flyer
6th March 2012, 11:37
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.

mentalmushroom
6th March 2012, 12:51
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.

high_flyer
6th March 2012, 13:39
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!