Time for action – creating items with different origins
Let's have a closer look at these three items defined by the following code snippet:
QGraphicsRectItem *itemA = QGraphicsRectItem(-10, -10, 20, 20); QGraphicsRectItem *itemB = QGraphicsRectItem(0, 0, 20, 20); QGraphicsRectItem *itemC = QGraphicsRectItem(10, 10, 20, 20);
What just happened?
All three items are rectangles with a side length of 20 pixels. The difference between them is the position of their coordinate origin points. itemA
has its origin in the center of the rectangle, itemB
has its origin in the top-left corner of the rectangle, and itemC
has its origin outside the drawn rectangle. In the following diagram, you see the origin points marked as red dots.
So what's the deal with these origin points? On the one hand, the origin point is used to create a relation between the item's coordinate system and the scene's coordinate system. As you will see later in more detail, if you set the position of the item on the scene, the position...