Conversions between coordinate systems

If an item is simply moved using setPos(), conversion from the item's coordinates to the scene coordinates is as simple as sceneCoord = itemCoord + item->pos(). However, this conversion quickly becomes very complex when you use transformations and parent–child relationships, so you should always use dedicated functions to perform such conversions. QGraphicsItem provides the following functions:

Function Description

mapToScene( const QPointF &point)

Maps the point point that is in the item's coordinate system to the corresponding point in the scene's coordinate system.

scenePos()

Maps the item's origin point to the scene's coordinate system. This is the same as mapToScene(0, 0).

Get Game Programming using Qt 5 Beginner's Guide - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.