Results 1 to 9 of 9

Thread: Event filter: very confused about how they work

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #7
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,349
    Qt products
    Qt5
    Platforms
    Windows
    Thanks
    318
    Thanked 872 Times in 859 Posts

    Default Re: Event filter: very confused about how they work

    So all you have to do is something like this:

    Qt Code:
    1. class Filter1 : public QObject
    2. {
    3. Q_OBJECT;
    4.  
    5. public:
    6. bool eventFilter( QObject * object, QEvent * event )
    7. {
    8. //... examine the event and return true or false
    9. }
    10. };
    11.  
    12. class Filter2 : public QObject
    13. {
    14. Q_OBJECT;
    15.  
    16. public:
    17. bool eventFilter( QObject * object, QEvent * event )
    18. {
    19. //... examine the event and return true or false
    20. }
    21. };
    22.  
    23. // Somefile.cpp
    24.  
    25. QFrame * frame1 = new QFrame( this );
    26. QFrame * frame2 = new QFrame( this );
    27.  
    28. Filter1 * filter1 = new Filter1( this );
    29. Filter2 * filter2 = new Filter2( this );
    30.  
    31. frame1->installEventFilter( filter1 );
    32. frame2->installEventFilter( filter2 );
    To copy to clipboard, switch view to plain text mode 

    So now all events for frame1 will be sent first to the filter1 instance of Filter1, likewise for frame2. If either filter eats the event, the respective frame will not see it. Otherwise, after the filter is done with it, the event will then be forwarded to the frame. In the eventFilter() method for filter1, the QObject argument will point to frame1, likewise for filter2.

  2. The following user says thank you to d_stranz for this useful post:

    papillon (19th November 2011)

Similar Threads

  1. Event filter with mouse events
    By felo188 in forum Qt Programming
    Replies: 13
    Last Post: 22nd July 2011, 10:57
  2. Event filter question
    By d_stranz in forum Qt Programming
    Replies: 7
    Last Post: 7th July 2011, 23:08
  3. Replies: 0
    Last Post: 28th August 2010, 14:22
  4. problem with event filter compile for S60
    By jimiq in forum Qt for Embedded and Mobile
    Replies: 1
    Last Post: 6th July 2010, 19:48
  5. Event Filter & No Focus problem
    By AlexanderPopov in forum Newbie
    Replies: 0
    Last Post: 22nd December 2009, 20:15

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
  •  
Qt is a trademark of The Qt Company.