PDA

View Full Version : QGraphicsItem -> boundingRect()



harakiri
6th March 2008, 12:17
hi,

i've got a problem with a QGraphicsItem. I wrote a class GraphicsLine:

GraphicsLine::GraphicsLine( int id, qreal x1, qreal y1, qreal x2, qreal y2 ) : QGraphicsItem()

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?

jpn
6th March 2008, 12:54
Did you notice QGraphicsLineItem? :)

PS. Don't link to external sites but attach images, please.

Gopala Krishna
6th March 2008, 12:59
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.

harakiri
6th March 2008, 14:13
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?

Gopala Krishna
6th March 2008, 15:02
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.