Results 1 to 7 of 7

Thread: How to prevent Event Propagation to Parent?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts

    Default Re: How to prevent Event Propagation to Parent?

    Wait, are you using QWidget::mousePressEvent() or QWidget::contextMenuEvent() to show the context menu? It should be the latter. Accepting an event stops the event propagation.
    J-P Nurmi

  2. #2
    Join Date
    Mar 2007
    Location
    India
    Posts
    27
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    5

    Default Re: How to prevent Event Propagation to Parent?

    Quote Originally Posted by jpn View Post
    Wait, are you using QWidget::mousePressEvent() or QWidget::contextMenuEvent() to show the context menu? It should be the latter. Accepting an event stops the event propagation.
    The code for showing the Context-Menu is implemented using mousePressEvent(). It's not my code ownership and is already existing so cant do much about it.

    But here the case is different I think. Coz the child object is myWidgetClass and the parent is myFrameClass. And in myWidgetClass I _am_ accepting() the event so meanging which it should not propagate further to its parent, right?

    Anyway, I'm looking into eventFilter(QObject *obj, QEvent *event) now. Hope I find something useful!

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,373
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    3
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: How to prevent Event Propagation to Parent?

    This works quite well for me, so you must have messed something up.
    Please note that this approach is the worst you could take. The best would be to use the context menu event and a worse but still better than using mousePress is to use mouseReleaseEvent.
    Attached Files Attached Files

  4. The following user says thank you to wysota for this useful post:

    viking (9th May 2007)

  5. #4
    Join Date
    Mar 2007
    Location
    India
    Posts
    27
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    5

    Exclamation Re: How to prevent Event Propagation to Parent?

    Quote Originally Posted by wysota View Post
    This works quite well for me, so you must have messed something up.
    Please note that this approach is the worst you could take. The best would be to use the context menu event and a worse but still better than using mousePress is to use mouseReleaseEvent.
    thanks! i dug into the code. it _was_ implemented using contextMenuEvent. but in spite of that and the accept() in the overridden procedure, the contextMenu still pops up. This is very weird!

Similar Threads

  1. The event fired by the mouse click on the frame
    By Placido Currò in forum Qt Programming
    Replies: 8
    Last Post: 3rd March 2007, 09:05
  2. Passing event to parent
    By QPissedOff in forum Newbie
    Replies: 1
    Last Post: 26th April 2006, 16:37
  3. Workload in a QThread blocks main application's event loop ?
    By 0xBulbizarre in forum Qt Programming
    Replies: 14
    Last Post: 9th April 2006, 21:55

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.