Results 1 to 7 of 7

Thread: Right click mouseReleaseEvents aren't caught by eventfilter,other events though are

  1. #1
    Join Date
    Oct 2010
    Posts
    21
    Thanks
    3
    Qt products
    Qt Jambi
    Platforms
    Unix/X11

    Default Right click mouseReleaseEvents aren't caught by eventfilter,other events though are

    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

    Qt Code:
    1. public boolean eventFilter(QObject o,QEvent event)
    2. {
    3. if (event.type()==QEvent.Type.MouseButtonPress) // One can call the mousePressEvent() functions from here,which can do this work but speed
    4. {
    5. if (((QMouseEvent)event).button()==Qt.MouseButton.LeftButton)
    6. {
    7. mousebuttontype=1;
    8. clickedorpressed=1;
    9. }
    10. else
    11. if (((QMouseEvent)event).button()==Qt.MouseButton.RightButton)
    12. {
    13. mousebuttontype=2;
    14. System.out.println("right");
    15. }
    16. t1=QTime.currentTime();
    17. t1.start();
    18. }
    19. else
    20. if (event.type()==QEvent.Type.MouseButtonRelease)
    21. {
    22. if (t1.elapsed()>900)
    23. {
    24. switch(mousebuttontype)
    25. {
    26. case 1: browser.back();
    27. break;
    28. case 2: browser.forward();
    29. break;
    30. }
    31. }System.out.println("choda");
    32. }
    33.  
    34. return false;
    35. }
    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.

  2. #2
    Join Date
    Oct 2010
    Posts
    21
    Thanks
    3
    Qt products
    Qt Jambi
    Platforms
    Unix/X11

    Default Re: Right click mouseReleaseEvents aren't caught by eventfilter,other events though a

    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 ?

  3. #3
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: Right click mouseReleaseEvents aren't caught by eventfilter,other events though a

    Is this even correct c++? At least, I haven't seen this before.

    Try
    Qt Code:
    1. QEvent::MouseButtonPress
    2. and
    3. QEvent::MouseButtonRelease
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Oct 2010
    Posts
    21
    Thanks
    3
    Qt products
    Qt Jambi
    Platforms
    Unix/X11

    Default Re: Right click mouseReleaseEvents aren't caught by eventfilter,other events though a

    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.

  5. #5
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: Right click mouseReleaseEvents aren't caught by eventfilter,other events though a

    Are you writing jave or C++ ?

  6. #6
    Join Date
    Oct 2010
    Posts
    21
    Thanks
    3
    Qt products
    Qt Jambi
    Platforms
    Unix/X11

    Default Re: Right click mouseReleaseEvents aren't caught by eventfilter,other events though a

    The code is in java.

  7. #7
    Join Date
    Oct 2010
    Posts
    21
    Thanks
    3
    Qt products
    Qt Jambi
    Platforms
    Unix/X11

    Default Re: Right click mouseReleaseEvents aren't caught by eventfilter,other events though a

    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.

Similar Threads

  1. How to get mouse click events outside the Qt window?
    By montylee in forum Qt Programming
    Replies: 11
    Last Post: 13th July 2015, 21:55
  2. Click events
    By Maluko_Da_Tola in forum Newbie
    Replies: 0
    Last Post: 26th August 2010, 01:05
  3. Handling mouse click events in QGraphicsItem
    By Luc4 in forum Qt Programming
    Replies: 7
    Last Post: 5th March 2010, 16:12
  4. Resize caught by select()
    By mhoover in forum Qt Programming
    Replies: 3
    Last Post: 17th July 2009, 04:04
  5. keyPressEvent not being caught
    By vieraci in forum Qt Programming
    Replies: 2
    Last Post: 29th October 2007, 12:53

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.