Results 1 to 8 of 8

Thread: How to deal the mouse event both in the child widget and parent widget?

  1. #1
    Join Date
    Oct 2009
    Posts
    32
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Question How to deal the mouse event both in the child widget and parent widget?

    I need deal the mouse event both in the child widget and parent widget, deal the mouse event in the parent widget first, then deal the mouse event in the child widget. Now I use the installEventFilter to monitor the child widget's event in the parent widget, but I find I can't receive the QEvent::MouseButtonPress and QEvent::MouseButtonRelease event in the parent widget's function eventFilter, but I can receive the child widget's paint, polish and other events. How to solve it? thanks.

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,716
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: How to deal the mouse event both in the child widget and parent widget?

    you are probably returning true after dealing with the event in your eventFilter method.
    You have to return true if you want the event to be processed on higher levels,
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. #3
    Join Date
    Oct 2009
    Posts
    32
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to deal the mouse event both in the child widget and parent widget?

    Sorry, I can't understand you. Can you explain it in detail? thanks.

  4. #4
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,716
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: How to deal the mouse event both in the child widget and parent widget?

    show your eventFilter() method, then I can show you in the code.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  5. #5
    Join Date
    Oct 2009
    Posts
    32
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to deal the mouse event both in the child widget and parent widget?

    I install the eventfilter in the statement: pWidget->installEventFilter(this); in the QDirectManipulationWrapPanel class.
    Now I can receive the pWidget's Paint, Polish and other event in the QDirectManipulationWrapPanel::eventFilter function,
    but I can't receive the QEvent::MouseButtonPress in the QDirectManipulationWrapPanel::eventFilter function. thanks.
    bool QDirectManipulationWrapPanel::eventFilter ( QObject * watched, QEvent * event )
    {

    if (watched == pWidget)
    {
    if (event->type() == QEvent::MouseButtonPress)
    {
    mousePressEvent((QMouseEvent*)event);
    }
    }
    return QWidget::eventFilter(watched, event);
    }

  6. #6
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,716
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: How to deal the mouse event both in the child widget and parent widget?

    Please use the code tags when posting code.

    Your eventFilter() is not doing enything with the event.
    How do you know that MouseButtonPress is not being trapped?
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  7. #7
    Join Date
    Oct 2009
    Posts
    32
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to deal the mouse event both in the child widget and parent widget?

    I already resolve the problem, thank you. I need receive the child's child event, but I only monitor the child widget's event. Now I can receive the MouseButtonPress event.

  8. #8
    Join Date
    Mar 2009
    Location
    Beijing
    Posts
    7
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: How to deal the mouse event both in the child widget and parent widget?

    Add the parent's parent widget's mouse event in the end of the mouse event in the parent widget.
    e.g. QParentWidget inhrets QWidget, in the mouse event of QParentWidget wrote following:
    void QParentWidget::mousePressEvent(QMouseEvent *event)
    {
    // do anything....
    QWidget::mousePressEvent(event);
    }

    void QChildWidget::mousePressEvent(QMouseEvent *event)
    {
    // do anything....
    }

Similar Threads

  1. How to Create child widget behind parent widget?
    By anupamgee in forum Qt Programming
    Replies: 6
    Last Post: 22nd June 2010, 13:03
  2. Replies: 4
    Last Post: 3rd October 2009, 08:19
  3. How to move child widget with parent widget?
    By anupamgee in forum Qt Programming
    Replies: 3
    Last Post: 19th June 2009, 15:23
  4. let parent widget grow with child widget?
    By BeS in forum Qt Programming
    Replies: 3
    Last Post: 17th February 2009, 11:17
  5. Move child widget along with the parent widget
    By sreedhar in forum Qt Programming
    Replies: 2
    Last Post: 15th May 2006, 12:00

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.