tags:

views:

39

answers:

2

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 in Jambi, but I hope I can modify an answer given in Qt for Jambi.

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;
 }

MY BASIC AIM IS GETTING THE TIME INTERVAL FOR WHICH THE RIGHT CLICK WAS PRESSED. ANY WORKAROUND ?

A: 

Some digging around certainly seems to suggest that there may be no right-mouse release event being generated if that is the trigger for a context menu on your particular system. These are conveyed as a QContextMenuEvent.

This Qt Labs post hints about this too.

A work around may be tricky if it is system dependent. Have you tried overriding event() in the QApplication class to see if the event comes through there? Some events don't necessarily get to the children but everything goes through QApplication::event().

Arnold Spence
Thanks. I subclassed QWebView and overrode the contextMenuEvent() slot to ignore context menu events. I handled the context menus in my application itself.
Daud
A: 

Another option for you is, subclass Qwebview and override mouseReleaseEvent event

Shadow
Thanks. I did just that. I subclassed QWebView and overrode the contextMenuEvent() slot to ignore context menu events. I handled the context menus in my application itself.
Daud
Nice, if you feel the answer is valuable mark as right so it may help to other who are in sick of this problem..
Shadow

related questions