[Qt-interest] Getting Coordinates of QGraphicsItem in absolute terms of another

Sean Harmer sean.harmer at maps-technology.com
Fri Oct 29 19:14:21 CEST 2010


Hi,

On Friday 29 October 2010 16:13:56 Michael Jackson wrote:
> I am displaying a QGraphicsView with a QGraphicsScene. Pretty basic stuff.
> I load up an image (Tiff: 1286x955 pixels w x h) and then allow the user
> to create a "selection" area using a combination of QRubberBand and a
> QGraphicsPolygonItem derived item. This all shows up just fine. I can
> select the "selection area" and move it around. I can resize it just fine.
> What I would like to do is show in the user interface (a QTableView to be
> precise) the upper left corner coordinates (in pixel coordinates) of that
> "selection area". I have all the signals/slots hooked up. I have a custom
> table model ready to go. The problem is that the values I get for things
> like the boundingRect seem relative to the initial position that the
> "selection area" was generated at? I have tried mapToScene, mapfromScene,
> mapToParent, mapFromParent and a few others but nothing is really making
> sense. A gently push in a direction would be greatly appreciated.

Would QGraphicsItem::mapFromItem( QGraphicsItem* item, const QPointF& ) do the 
trick? Possibly followed by a mapFromScene() as I am not quite sure exactly 
which coordinate system you wish you final answer to be in.

Cheers,

Sean



More information about the Qt-interest-old mailing list