PDA

View Full Version : Right click mouseReleaseEvents aren't caught by eventfilter,other events though are



daudiam
13th October 2010, 09:40
My application consists of a WebView widget. A mouse click on the widget is not handled by the mousePressEvent() of my application, but by the WebView widget. So, I installed an event filter to receive the events. Now, I get notified of all events, except the mouseReleaseEvent for the right click (Everything works fine for left clicks and mousePressEvent for the right click is also getting registered). I guess it has got something to do with context events getting generated by right clicks (a pop-up menu gets generated). But since I am using a filter, the event should first be sent to me. The following is the code for the event filter


public boolean eventFilter(QObject o,QEvent event)
{
if (event.type()==QEvent.Type.MouseButtonPress) // One can call the mousePressEvent() functions from here,which can do this work but speed
{
if (((QMouseEvent)event).button()==Qt.MouseButton.Lef tButton)
{
mousebuttontype=1;
clickedorpressed=1;
}
else
if (((QMouseEvent)event).button()==Qt.MouseButton.Rig htButton)
{
mousebuttontype=2;
System.out.println("right");
}
t1=QTime.currentTime();
t1.start();
}
else
if (event.type()==QEvent.Type.MouseButtonRelease)
{
if (t1.elapsed()>900)
{
switch(mousebuttontype)
{
case 1: browser.back();
break;
case 2: browser.forward();
break;
}
}System.out.println("choda");
}

return false;
}

On a right click, I get the message "right" but on releasing, I don't get "choda". I get both the messages for left clicks.

daudiam
13th October 2010, 17:41
Any workaround so that I can simply note the time for which the right mouse button is being pressed. I was setting the QTime object with the system time when the mousePress event was generated and when the mouseRelease event was generated, I caculated the elapsed time by calling the elapse() function. Works perfectly for left clicks, but for the right clicks only the mousePress event is being caught, not the mouseRelease event by my application (through the eventFilter slot). Any other way by which i can do this ?

tbscope
13th October 2010, 17:51
Is this even correct c++? At least, I haven't seen this before.

Try

QEvent::MouseButtonPress
and
QEvent::MouseButtonRelease

daudiam
13th October 2010, 18:06
he code I posted compiled correctly.

The code was in Qt Jambi. If you can point out the workaround for Qt, I can modify it for Jambi. My problem is that the context menu event generated by right clicking on the web page, somehow prevents me from receiving the mouseRelease event for the right click after I have received the mousePress event when the right click occured.

tbscope
13th October 2010, 18:39
Are you writing jave or C++ ?

daudiam
13th October 2010, 18:55
The code is in java.

daudiam
14th October 2010, 07:58
I did the following.

In subclassed QWebView and overrode te contextMenuEvent() slot so as to ignore the event. This enabled my application to receive the mouseRelease event. On the other hand, it forced my application to handle the context menu events, which I did. Thanks.