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
{
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.
LeftButton) {
mousebuttontype=1;
clickedorpressed=1;
}
else
if (((QMouseEvent)event
).
button()==Qt.
MouseButton.
RightButton) {
mousebuttontype=2;
System.out.println("right");
}
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;
}
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.LeftButton)
{
mousebuttontype=1;
clickedorpressed=1;
}
else
if (((QMouseEvent)event).button()==Qt.MouseButton.RightButton)
{
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;
}
To copy to clipboard, switch view to plain text mode
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.
Bookmarks