Results 1 to 5 of 5

Thread: QGraphicsPathItem changing state when hovered

  1. #1
    Join Date
    Apr 2010
    Posts
    34
    Thanks
    1
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QGraphicsPathItem changing state when hovered

    Hi,
    I have a "chart" view using QGraphicsView. Each line of data consists of few QGraphicsPathItems wrapped by a QGraphicsItemGroup. My intent is to highlight a data line when hovered by a mouse.

    Here comes the problem: The hover events on the group are sent when I hover the rect of the line, but not the line itself (which is a curve). What's more, when more data lines go over each other, only the "top" one receives the hover event (due to z order).
    I could implement a function which would iterate over points of the data lines, but don't want to reinvent a wheel in case I can do it simpler.

    So, does anybody know a way how to detect that a cursor is above the curve itself, not only the rectangular area it's bounded by?

    Thanks
    Vit

  2. #2
    Join Date
    Dec 2009
    Posts
    128
    Thanks
    7
    Thanked 14 Times in 14 Posts
    Platforms
    Unix/X11 Windows

    Default Re: QGraphicsPathItem changing state when hovered

    Did you subclass QGraphicsPathItem class ?
    If so, can you post the ::shape() method you defined for the subclass ?

    This is the method used by hover events to determine if you are "on" an item

  3. #3
    Join Date
    Apr 2010
    Posts
    34
    Thanks
    1
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QGraphicsPathItem changing state when hovered

    Nope, I'll try it. Now I think if the problem can't be caused by handling the event in the QGraphicsItemGroup object instead of the PathItem itself? I should know in few minutes...


    Added after 36 minutes:


    I have subclassed the QGraphicsPathItem class and implemented the hover event handlers as following:

    Qt Code:
    1. void hoverEnterEvent( QGraphicsSceneHoverEvent * )
    2. {
    3. m_isMouseOver = true;
    4. dbg( QString( "Hovered a path %1" ).arg( (int)this ) );
    5. }
    6.  
    7. void hoverLeaveEvent( QGraphicsSceneHoverEvent * )
    8. {
    9. m_isMouseOver = false;
    10. }
    To copy to clipboard, switch view to plain text mode 

    I also call setAcceptHoverEvents(true) from the ctor. But the event handler is never reached. Could be there a problem with the fact that it's a curve, so it has no area?
    Last edited by Vit Stepanek; 8th December 2010 at 15:15.

  4. #4
    Join Date
    Dec 2009
    Posts
    128
    Thanks
    7
    Thanked 14 Times in 14 Posts
    Platforms
    Unix/X11 Windows

    Default Re: QGraphicsPathItem changing state when hovered

    I did not read before, but documentation states that "A QGraphicsItemGroup is a special type of compound item that treats itself and all its children as one item (i.e., all events and geometries for all children are merged together)"

    Is it mandatory to group all paths in a QGraphicsItemGroup ?

  5. #5
    Join Date
    Apr 2010
    Posts
    34
    Thanks
    1
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QGraphicsPathItem changing state when hovered

    Well, that's a question. I use my class that's derived from QGraphicsItemGroup to fill it with measured data, each represents some measured feature in the time (x axis). However, the new data can be added to the existing displayed line.
    But using some merging functionality I could avoid having the QGraphicsItemGroup used. Let me try.

    Thanks

Similar Threads

  1. How to identify drag hovered items in itemviews?
    By happy11wl in forum Qt Programming
    Replies: 2
    Last Post: 1st June 2010, 13:08
  2. Set a ToolButton Hovered
    By vajindarladdad in forum Newbie
    Replies: 7
    Last Post: 1st September 2009, 13:33
  3. QGraphicsPathItem
    By tonio in forum Qt Programming
    Replies: 4
    Last Post: 25th June 2009, 15:35
  4. QGraphicsPathItem - slow on Mac, fine on X11
    By aeh in forum Qt Programming
    Replies: 0
    Last Post: 18th May 2009, 13:42
  5. QGraphicsPathItem Doubt
    By arjunasd in forum Qt Programming
    Replies: 7
    Last Post: 29th July 2007, 04:30

Tags for this Thread

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.