Results 1 to 10 of 10

Thread: QGraphicsItem - clipping all child mouse events that are outside of parent

  1. #1
    Join Date
    Sep 2006
    Location
    Belgrade
    Posts
    28
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default QGraphicsItem - clipping all child mouse events that are outside of parent

    The thing I would like to do is to make a container item (widget) and to scroll other items inside it. (a scroll-box of sorts)

    I've set the ItemClipsChildrenToShape flag so that children do not get painted outside of the container widget.

    The problem is that clipped parts of the contained widgets receive mouse hover and leave events (possibly other events too, I havent checked)

    Is there a way to inhibit the mouse (hover and leave) events for the parts of the widgets that are not shown? (handlesChildEvents doesn't apply to hover events, according to docs)

    Cheers!
    While you were hanging yourself on someone else's words
    Dying to believe in what you heard
    I was staring straight into the shining sun

  2. #2
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QGraphicsItem - clipping all child mouse events that are outside of parent

    Where are u catching the events ??
    It shouldnt happen that area outside widget gets events

  3. #3
    Join Date
    Sep 2006
    Location
    Belgrade
    Posts
    28
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: QGraphicsItem - clipping all child mouse events that are outside of parent

    Well, technically, it is not outside of the widget - it is inside the child widget, but outside of the parent.

    You can see what I mean in the attachment.

    So, the events occur in the not visible (clipped by parent) parts of the child widget. (it is represented by the mouse pointer hovering the clipped part of the 3rd child widget in the mockup)

    As the documentation states, it *is* the correct behaviour, but it is illogical when the children are clipped to parent.

    Unfortunately it can't be done by checking whether parent and child are hovered since parent thinks it is hovered when one of the children are.
    Attached Images Attached Images
    While you were hanging yourself on someone else's words
    Dying to believe in what you heard
    I was staring straight into the shining sun

  4. #4
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QGraphicsItem - clipping all child mouse events that are outside of parent

    Two questions -

    1) Why cant u increase parent to include all the children in it ?

    2)
    Unfortunately it can't be done by checking whether parent and child are hovered since parent thinks it is hovered when one of the children are.
    why so ? if u override the hoverevent in child item and check if that point lies in the parent or not, u can ignore it ?
    if(parent()->contains()->mapToParent(event->pos())....
    hope u get the idea

  5. #5
    Join Date
    Sep 2006
    Location
    Belgrade
    Posts
    28
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: QGraphicsItem - clipping all child mouse events that are outside of parent

    Quote Originally Posted by aamer4yu View Post
    1) Why cant u increase parent to include all the children in it ?
    Well, as I said, I want to implement a scroll-pane like widget - it is meant not to show all items - it has to have a fixed size and to provide mechanism for scrolling items in it (scroll bars etc.)

    Quote Originally Posted by aamer4yu View Post
    why so ? if u override the hoverevent in child item and check if that point lies in the parent
    I know what you mean, but the scroll pane should be general enough to hold any subclass of QGrItem, so I can not override children's methods.
    While you were hanging yourself on someone else's words
    Dying to believe in what you heard
    I was staring straight into the shining sun

  6. #6
    Join Date
    Jun 2008
    Posts
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QGraphicsItem - clipping all child mouse events that are outside of parent

    Have you any success with hover events? I'm implementing scroll areas as QGraphicsItems too. Is your code public?

  7. #7
    Join Date
    Sep 2006
    Location
    Belgrade
    Posts
    28
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: QGraphicsItem - clipping all child mouse events that are outside of parent

    Well, I haven't done anything yet. Had a couple things to do before that. The possibilities as I see them are:
    - override the hover events in children (as suggested by aamer4yu) which I don't like for mentioned reasons
    - use a QGraphicsView as a widget on canvas - inside another QGraphicsView. I don't like this approach since it could potentially introduce presently unforeseen problems, and breaks the MVC in a sense
    - do nothing and don't care. And leave the filtering to children if they want to be filtered. This approach is possibly the best since it could incorporate the first two in it.

    As for the code, it is in http://websvn.kde.org/trunk/KDE/kdep...lets/lancelot/ but as I said, currently there is no code for this. The current implementation for the list views uses a fancy-looking dirty hack of resizing items on the edges so that they fit into the view.
    While you were hanging yourself on someone else's words
    Dying to believe in what you heard
    I was staring straight into the shining sun

  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: QGraphicsItem - clipping all child mouse events that are outside of parent

    I just scanned through this thread so what I suggest may have already been tried by you and if that is the case, sorry for the fuzz. Have you tried using scene event filters? You could filter all events in the container item and check whether the target item is inside or outside your shape or bounding rect and based on that discard the event (return true) or let it reach the child (return false).
    Last edited by wysota; 22nd June 2008 at 21:08. Reason: corrected contents

  9. #9
    Join Date
    Sep 2006
    Location
    Belgrade
    Posts
    28
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: QGraphicsItem - clipping all child mouse events that are outside of parent

    @wysota
    The idea is ok, but there is a small problem:
    1. If we use the mouse move event to detect /hovers/ and /leaves/ it has a bigger performance impact than it should (on every move, we should check whether it is in or out)
    2. If we don't do it that way but only filter the hover/leave events, then we get a bug when we hover the clipped part of the QGrItem, and move the mouse to the non-clipped part since we will not receive another event for that.
    While you were hanging yourself on someone else's words
    Dying to believe in what you heard
    I was staring straight into the shining sun

  10. #10
    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: QGraphicsItem - clipping all child mouse events that are outside of parent

    At least you get proper behaviour for items that are completely disjoint from their parent. For others you might try some heuristics or hybrid approaches.

Similar Threads

  1. Handling Mouse Events of a parent widget
    By dvmorris in forum Qt Programming
    Replies: 2
    Last Post: 28th March 2007, 18:44
  2. QStackerWidget and mouse events
    By high_flyer in forum Qt Programming
    Replies: 3
    Last Post: 25th April 2006, 19:25

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.