Where is the point (0,0) (in item coordinates) of a QGraphicsPolygonItem ?
-
Hello,
When I build a QGraphicsPolygonItem like this:
@poly << QPointF(0, -sqrt(12)) << QPointF(-2, 0) << QPointF(2, 0); //equilateral triangle
QGraphicsPolygonItem polygon;
polygon.setPolygon(poly);@
Where is the ponit (0,0) in the item coordinates ?
There is nothing in the doc.Thank you.
-
As in whole Graphics View Framework, (0,0) is in the top left corner.
-
Note quite, I seem to remember. (0,0) is the origin of the item, and the coordinate system is such that positive Y is under the (0,0) point and positive X to the right of the point. So far, we agree. However, you are allowed to use negative coordinates for drawing your item as well. That means that if you decide to draw a rectangle (-100, -100),(0,0), then you will have (0,0) in the lower right corner. Do not forget to return the correct bounding rect for your item.
-
@Cpowa, as I understand from Andre
s answer QGraphicsPolygonItem has a bounding rectangle and 0,0 is at it
s lower right corner. -
There are no "corners". Items have their own local coordinate system, which is "infinite" in any direction (actually it's bounded by what you can represent with a qreal, but ...). (0, 0) is the origin, Y growns downwards and X grows rightwards (but of course you can apply a transformation).
-
[quote author="task_struct" date="1314781082"]@Cpowa, as I understand from Andre
s answer QGraphicsPolygonItem has a bounding rectangle and 0,0 is at it
s lower right corner. [/quote]Then you misunderstood my post. My point was, that (0,0) is not a fixed point for any item. It is just the origin of the coordinate system, but because you are allowed to use negative coordinates, the actual drawing of the item could happen anywhere relative to this point. You can make (0,0) the upper left or the lower right corner of your item, but you can also make it the center, or draw you item so that (0,0) is completely outside your item. Bottom line: (0,0) can be anywhere. It is another question whether it should, of course.