Qt World Summit: Register Today!

Problem with Items coordinate system

  • While making a videogame I have had a problem due to the fact that probably I misunderstood how items coordinates system works. In particular in order to know the position in the scene of the mushroom(goomba) in the picture posted below, which is a gridded screenshot of my game, I wrote this line of code:

    std::cout << goomba->scenePos().toPoint().x() << " " << goomba->scenePos().toPoint().y() ;

    Now every box in the grid is a square of 16*16 pixels and I set scene's origin so that it's in the top-left corner of that grid in particular it's the top-left corner of the square with number 0.
    As I have read in Qt Documentation and according to this picture of Summerfiled's book on Qt

    I have learned that an item's position is the coordinate of the item's center point in its parent's coordinate system but since the mushroom is a top level item its position is in scene coordinates .
    The code I wrote prints the top-left corner of the item in scene coordinates as if it is the position of the item but according to what I know it should print the center point of the item ,in scene coordinates, which I know to be its position.
    So what is the position of a top level item? Is it the top-left corner or the center point of the item?

  • Lifetime Qt Champion

    Hi and welcome to devnet,

    Can you point where in the documentation you saw that center coordinate ?

  • Hi. Here


    I am making confusion between an item's position and its center point probably beacuse I misunderstood this statement in documentation


    In particular if the scene is the parent of the item what is the item's position?

  • Lifetime Qt Champion

    This just means that every item has it's own coordinate system with 0,0 as it's center point used for transformations. So If you want to rotate an item in it's , you should put it's center at 0,0 - otherwise rotate() will not do what you expect.

  • Ok , I understood that. But if the item is a top level one its position in the scene is identified by its top-left point expressed in scene coordinates, am I right?

  • Lifetime Qt Champion

    Yes, that's correct.

Log in to reply