Results 1 to 11 of 11

Thread: Graphics View Event Propagation

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Aug 2006
    Posts
    250
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    19
    Thanked 49 Times in 36 Posts

    Default Re: Graphics View Event Propagation

    Quote Originally Posted by wysota View Post
    No, subclass, reimplement the event handler in it and ignore() the event there. It'll get propagated to the parent then (but you won't be able to move the item using mouse).
    Hmm, I tried this, but the event still does not get propagated to the parent. Very strange. I get the event in the QGraphicsTextItem subclass, and properly ignore() it, but it still never reaches the QGraphicsItem behind it.

    I don't know what your "box" item does, but maybe it'd be simpler to subclas QGraphicsTextItem and modify its behaviour so that it draws the frame?
    Well that wouldn't be easily possible, but I found a another way to work around the problems. Now I just set setHandlesChildEvents(true) on the parent item when I don't want the textitem to be editable, and when I do, I clear that flag. Selecting text with the mouse still doesn't work though. Maybe I'll start another thread for that problem to avoid confusion.

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

    Default Re: Graphics View Event Propagation

    Quote Originally Posted by pherthyl View Post
    Hmm, I tried this, but the event still does not get propagated to the parent.
    It's almost not possible. You might have done something wrong. The only possibility is that there is an event filter applied on the item and it handles the event instead of the regular handler.

    Very strange. I get the event in the QGraphicsTextItem subclass, and properly ignore() it, but it still never reaches the QGraphicsItem behind it.
    In that case there is no filter Is the graphics item behind it the parent of the text item?

  3. #3
    Join Date
    Aug 2006
    Posts
    250
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    19
    Thanked 49 Times in 36 Posts

    Default Re: Graphics View Event Propagation

    Quote Originally Posted by wysota View Post
    It's almost not possible. You might have done something wrong.
    Quite likely yes

    In that case there is no filter Is the graphics item behind it the parent of the text item?
    Yes. Does being the parent make events not propagate?

  4. #4
    Join Date
    Aug 2006
    Location
    Bangalore,India
    Posts
    419
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11
    Thanks
    37
    Thanked 53 Times in 40 Posts

    Default Re: Graphics View Event Propagation

    hmm... looks quite confusing.. I had a look at the QGraphicsItem::sceneEvent() and i found this
    Qt Code:
    1. bool QGraphicsItem::sceneEvent(QEvent *event)
    2. {
    3. if (d_ptr->ancestorFlags & QGraphicsItemPrivate::AncestorHandlesChildEvents) {
    4. if (event->type() == QEvent::HoverEnter || event->type() == QEvent::HoverLeave
    5. || event->type() == QEvent::DragEnter || event->type() == QEvent::DragLeave) {
    6. // Hover enter and hover leave events for children are ignored;
    7. // hover move events are forwarded.
    8. return true;
    9. }
    To copy to clipboard, switch view to plain text mode 
    May be this is causing some side effect since you are igonoring the hover event. Not sure though. IMHO you should post a simple example. It will make us understand in a better way.

    BTW did you try calling
    Qt Code:
    1. QGraphicsTextItem::setAcceptHoverEvents(false);
    To copy to clipboard, switch view to plain text mode 
    EDIT: If you are doing the above there is no need to reimplement hoverEvent methods as far as i have understood.
    Note that QGraphicsTextItem enables hover events while constructing.
    Also call setAcceptHoverEvents(true) on your parent item otherwise the handlers are not called.
    Its worth to have a look at the documentation of QGraphicsItem::setAcceptsHoverEvents ( )
    Last edited by Gopala Krishna; 12th August 2007 at 07:14.
    The biggest difference between time and space is that you can't reuse time.
    -- Merrick Furst

  5. #5
    Join Date
    Jan 2006
    Location
    Norway
    Posts
    124
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows
    Thanked 38 Times in 30 Posts

    Default Re: Graphics View Event Propagation

    If someone can show a sample subclass that ignores the event, it'll be easier to see what's going on. The code in sceneEvent() is for filtering away enter and leave events for items that handle child events - it's a special thing for hover events to let you track the mouse motion over all children, avoiding having to check whether enter and leave events were for the parent or the child, or whatever :-). Hover events and mouse events are handled differently, though...
    Bitto / Andreas Aardal Hanssen - andreas dot aardal dot hanssen at nokia
    Nokia Software Manager, Qt Development

  6. #6

    Default Re: Graphics View Event Propagation

    Hmm I was confused by this for a while, but it looks like the parent object needs to have the flags:

    setFlag(QGraphicsItem::ItemIsMovable, true);
    setFlag(QGraphicsItem::ItemIsSelectable, true);

    in order for the text interaction to work right.

Similar Threads

  1. Qt Coordinate System and the Graphics View Framework
    By djurodrljaca in forum Qt Programming
    Replies: 14
    Last Post: 17th February 2012, 11:19
  2. Graphics view display problem.
    By kiranraj in forum Qt Programming
    Replies: 3
    Last Post: 20th July 2007, 07:08
  3. graphics view FitInView problem
    By aamer4yu in forum Qt Programming
    Replies: 6
    Last Post: 25th January 2007, 10:24
  4. which is better QCanvas or graphics view?
    By neomax in forum General Discussion
    Replies: 1
    Last Post: 23rd November 2006, 15:19
  5. Adding Rectangular overlay on graphics view
    By forrestfsu in forum Qt Programming
    Replies: 10
    Last Post: 21st November 2006, 19:42

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.