O'Reilly logo

Game Programming using Qt 5 Beginner's Guide - Second Edition by Lorenz Haas, Witold Wysota, Pavel Strakhov

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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).

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required