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

Michael Jackson mike.jackson at bluequartz.net
Fri Oct 29 20:42:09 CEST 2010


On 10/29/10 1:14 PM, in article
201010291814.21872.sean.harmer at maps-technology.com, "Sean Harmer" wrote:

> 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
I think that is the same as mapFromParent(Qpoint) as I set the image as the
"selection area's" parent. I think this is what is giving me what I want:

QPoint p = pos().toPoint();
QRect b = boundingRect().toAlignedRect();
std::cout << "combined rect: " << b.x()+p.x() << ", " << b.y()+p.y() <<
std::endl;

I wanted the final values to be the pixel coordinates that are the
"selection area" covers in the original image.

Thanks for the heads up
Mike Jackson




More information about the Qt-interest-old mailing list