Results 1 to 5 of 5

Thread: QGraphicsItem -> boundingRect()

  1. #1
    Join Date
    May 2007
    Posts
    33
    Thanks
    9
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QGraphicsItem -> boundingRect()

    hi,

    i've got a problem with a QGraphicsItem. I wrote a class GraphicsLine:
    Qt Code:
    1. GraphicsLine::GraphicsLine( int id, qreal x1, qreal y1, qreal x2, qreal y2 ) : QGraphicsItem()
    To copy to clipboard, switch view to plain text mode 

    In order to do so, i had to reimplementent boundingRect. I want each Object of GraphicsLine to change it's color to red if the mouse is hovered above it.
    So far, everything works fine.

    But if two lines cross each other, only the most recently painted one changes it color because it's bounding box lies above the other one.

    Example attached

    how can i mark all lines underneath the mouse pointer?
    Attached Images Attached Images
    Last edited by harakiri; 6th March 2008 at 14:11.

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QGraphicsItem -> boundingRect()

    Did you notice QGraphicsLineItem?

    PS. Don't link to external sites but attach images, please.
    J-P Nurmi

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

    Default Re: QGraphicsItem -> boundingRect()

    Hover events are delivered to only toplevel items. Probably you can then send hover events to underlying items manually from the hover event of line item.
    The biggest difference between time and space is that you can't reuse time.
    -- Merrick Furst

  4. #4
    Join Date
    May 2007
    Posts
    33
    Thanks
    9
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QGraphicsItem -> boundingRect()

    Quote Originally Posted by Gopala Krishna View Post
    Hover events are delivered to only toplevel items. Probably you can then send hover events to underlying items manually from the hover event of line item.
    how would you do that?

    how can i find out which items are underneath the current one?

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

    Default Re: QGraphicsItem -> boundingRect()

    Quote Originally Posted by harakiri View Post
    how would you do that?

    how can i find out which items are underneath the current one?
    You can use QGraphicsItem::collidingItems() method to get a list of items colliding each other. By underneath i think you are using QGraphicsItem::zValue() in which case you can use that to determine whether it is above or below.
    You can either just directly call the hover events of the items or use QCoreApplication::postEvent().
    Make sure you don't go into infinite recursion, keep track of items which have already received hover events.
    The biggest difference between time and space is that you can't reuse time.
    -- Merrick Furst

Similar Threads

  1. QGraphicsView, QGraphicsItem, QGraphicsScene
    By Shuchi Agrawal in forum Newbie
    Replies: 10
    Last Post: 23rd March 2011, 21:50
  2. destruction of QGraphicsItem
    By killkolor in forum Qt Programming
    Replies: 2
    Last Post: 5th December 2009, 11:31
  3. rotation of an animated QGraphicsItem
    By darksaga in forum Qt Programming
    Replies: 9
    Last Post: 9th September 2007, 09:11
  4. Force the painting of a QGraphicsItem
    By fabietto in forum Qt Programming
    Replies: 3
    Last Post: 2nd July 2007, 22:28
  5. QGraphicsItem and signals
    By aamer4yu in forum Qt Programming
    Replies: 3
    Last Post: 27th December 2006, 12:19

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.