Results 1 to 4 of 4

Thread: Eventfilter gets form instead of label

  1. #1
    Join Date
    May 2012
    Posts
    136
    Thanks
    2
    Thanked 27 Times in 24 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Eventfilter gets form instead of label

    Hello all,

    I'm creating a virtual right mouse button, this is only used in the Qt application. Holding down the left mouse button for 750 msec it will send a ContextMenuEvent. This is usefull for touchscreen users, and not willing to enable global virtual right mouse button.

    Now the real problem/challenge
    I've made a VirtualRightMouseButton class which installs an eventfilter by using qApp->installEventFilter(...
    When i hold the left mouse button on an editbox or some other editor it works perfectly (and opens a context menu), now when i use it on a label it doesn't show a context menu (yes i know it doesn't have a default context menu, so i added an customcontextmenu, when normal right clicking it, it works and shows the custom context menu)
    after a while of debugging i found that the eventfilter gets the container class instead of the label (in this case the QMainWindow and not the QLabel) does anyone know why

    Thanks in advance.

    edit: It also works normally on QButtons

  2. #2
    Join Date
    May 2012
    Posts
    136
    Thanks
    2
    Thanked 27 Times in 24 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Eventfilter gets form instead of label

    I've found the problem myself
    When clicking a QLabel there are multiple click events fired
    the first is QLabel then the second is the QMainFrame

  3. #3
    Join Date
    Sep 2011
    Location
    Manchester
    Posts
    538
    Thanks
    3
    Thanked 106 Times in 103 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Eventfilter gets form instead of label

    Maybe just filter out context menu events coming from QMainWindow or other widgets that you do not support.
    Qt Code:
    1. bool MainWindow::eventFilter( QObject* o, QEvent* e )
    2. {
    3. if( o == && e->type() == QEvent::ContextMenu )
    4. {
    5. return true;
    6. }
    7. return QMainWindow::eventFilter( o, e );
    8. }
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    May 2012
    Posts
    136
    Thanks
    2
    Thanked 27 Times in 24 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Eventfilter gets form instead of label

    Thank you for you're reply Spitfire

    The virtual right mouse button needs to filter the left mouse click and check if it is held for 750ms, i don't have to filter the context menu event, this is the even that I send when the mouse is clicked for 750ms.

    I've solved it by just filtering out the first mouse down event (leftbutton), the events are fired in order of visibility and the QLable is on top/first.

Similar Threads

  1. Replies: 7
    Last Post: 23rd May 2012, 12:00
  2. Yet another eventFilter question
    By ls4f in forum Qt Programming
    Replies: 8
    Last Post: 14th September 2011, 13:50
  3. How to hide from taskbar a form showed form mainwindow
    By tonnot in forum Qt Programming
    Replies: 1
    Last Post: 10th February 2011, 14:36
  4. Insert picture in a form using label
    By cwnelatury in forum Newbie
    Replies: 14
    Last Post: 18th March 2010, 23:43
  5. QTreeWidget and eventFilter
    By luoyes in forum Qt Programming
    Replies: 2
    Last Post: 5th November 2009, 06:38

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.