Results 1 to 10 of 10

Thread: mouse events and nested widgets

  1. #1
    Join Date
    Jul 2012
    Posts
    244
    Thanks
    27
    Thanked 15 Times in 14 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default mouse events and nested widgets

    Hi,

    i have a custom widget, that consists of three single widgets. Ie. w1 contains w2, which contains w3.
    This works just fine.

    The problem: w3 receives TWO mousemove events for every MouseMove.
    The two event positions are slightly different, suggesting that the events are fired by w1 and w2, and that the position is relative to the causing widget.


    This seems to only happen with "mouseMoveEvent( QMouseEvent *event )" events.

    What to do about this? :/

  2. #2
    Join Date
    Jul 2012
    Posts
    244
    Thanks
    27
    Thanked 15 Times in 14 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: mouse events and nested widgets

    c`mon guys, dont ignore me...

  3. #3
    Join Date
    Feb 2011
    Location
    Bangalore
    Posts
    207
    Thanks
    20
    Thanked 28 Times in 27 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: mouse events and nested widgets

    Event propogation differs in QWidgets and QGraphicsItem related classes. Assuming that you are dealing with QWidgets here. The event is dispatched to the object (lowest level in hierarchy) first, if no event filters are installed. Basically lowest level object's event function is called and depending on the event type it is given to specific function which in your case happens to be mouseMoveEvent().
    Now the way event propogates is if event->ignore() is called, it goes to the parent. if event->accept() is called it doesnot. Now the default version of your QWidget version of mousemoveevent() function or other functions like it calls event->ignore() in it. So if in your QWidget subclass you happen to call the base version of function, it will lead to propogation.
    So bottomline is, for the case you have handled in mouseMoveEvent(), AVOID calling the base class version from it. You will not need to call event->accept() becoz it is done by default.
    Hope it helps.

  4. #4
    Join Date
    Jul 2012
    Posts
    244
    Thanks
    27
    Thanked 15 Times in 14 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: mouse events and nested widgets

    AVOID calling the base class version from it.
    what do you mean by base class version here? I dont call anything myself...
    There is a mistake in my first post, it`s actually a QAbstractScrollArea that is encapsulated by two widgets.
    so: Qwidget(Qwidget(QAbstractScrollArea))).

    In my QAbstractScrollArea-class i have a function "mouseMoveEvent", which is called twice as described above. The two widgets QAbstractScrollArea is wrapped in dont handle mouseMoveEvent at all.

    Note that the problem is not directly propagation, the two mouseMoveEvents i receive are for two different locations. However, it seems that relative to the two wrapping widgets, it`s the same event/position.

  5. #5
    Join Date
    Feb 2011
    Location
    Bangalore
    Posts
    207
    Thanks
    20
    Thanked 28 Times in 27 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: mouse events and nested widgets

    Quote Originally Posted by tuli View Post
    what do you mean by base class version here? I dont call anything myself...
    There is a mistake in my first post, it`s actually a QAbstractScrollArea that is encapsulated by two widgets.
    so: Qwidget(Qwidget(QAbstractScrollArea))).
    I mean in ur QWidget inherited class where you write mouseMoveEvent function, don't write QWidget::mouseMoveEvent(). Doing so results in propogation up the parent tree.
    Quote Originally Posted by tuli View Post
    Note that the problem is not directly propagation, the two mouseMoveEvents i receive are for two different locations. However, it seems that relative to the two wrapping widgets, it`s the same event/position.
    mouseMoveEvents come in a continuous stream. Because it is mouseMoveEvent!! QMouseEvent:os() depends upon widget being mouse tracked off or on. Unless you show some code, it will be difficult to help.

  6. #6
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: mouse events and nested widgets

    The problem: w3 receives TWO mousemove events for every MouseMove.
    How can you say so?
    The two event positions are slightly different, suggesting that the events are fired by w1 and w2, and that the position is relative to the causing widget.
    Show an example
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

  7. #7
    Join Date
    Jul 2012
    Posts
    244
    Thanks
    27
    Thanked 15 Times in 14 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: mouse events and nested widgets

    How can you say so?
    When i breakpoint mouseMoveEvent is break twice for one mousmove, usually i break once.
    Additionally, the y coordinate differs, even though i only moved the mouse vertically.

    I`ll try to reproduce this on a smaller scale now.

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

    Default Re: mouse events and nested widgets

    Please show your mouseMoveEvent() implementation. And tell us which class it belongs to.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  9. #9
    Join Date
    Jul 2012
    Posts
    244
    Thanks
    27
    Thanked 15 Times in 14 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: mouse events and nested widgets

    sorry, i cant check out the problematic code right now, i`ll be back monday.

  10. #10
    Join Date
    Jul 2012
    Posts
    244
    Thanks
    27
    Thanked 15 Times in 14 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: mouse events and nested widgets

    hi guys, sorry for the delay.

    Our servers were down for some time, then i was gone for two days - and pof - the problem disappeared, even though i cannot see any relevant changes to the code in question.
    I´ll be searching through commits some more next week.

Similar Threads

  1. Replies: 3
    Last Post: 12th August 2012, 13:49
  2. Replies: 3
    Last Post: 8th October 2011, 09:46
  3. Replies: 2
    Last Post: 10th June 2010, 05:58
  4. mouse events
    By xyzt in forum Newbie
    Replies: 3
    Last Post: 23rd March 2008, 11:14
  5. mouse moving don't produce mouse events
    By coralbird in forum Qt Programming
    Replies: 1
    Last Post: 13th September 2006, 06:13

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.