Position in scene coordinates
I am learning about graphic view, I have written simple code to check how it behave and I don't know how to get position of items in scene coordinates:/
@Widget::Widget(QWidget *parent) :
scene = new QGraphicsScene(-200,-200,400,400);
ellipse=scene->addEllipse(-50,-50,100,100,blackpen,redBrush); rec->setFlag(QGraphicsItem::ItemIsMovable); qDebug()<<ellipse->scenePos(); qDebug()<<ellipse->pos();
Qt documentation says about pos():
bq. .., If the item has no parent, its position is given in scene coordinates.
The position of the item describes its origin (local coordinate (0, 0)) in parent coordinates; this function returns the same as mapToParent(0, 0).
For convenience, you can also call scenePos() to determine the item's position in scene coordinates,..
but qDebug shows for both (pos and scenePos) "QPointF(0, 0)" I suppose its point from local scene.
When you add the rects with addRect you are defining the size of each rect, but not the position.
The pos() function will give a position relative to the item's parent, which in the case of your code is the scene, so they're the same.
If you create two rects A and B and make B a child of A, then add rect A to the scene, you can move B and see that the functions pos() and scenePos() are different.
Hope that helps ;O)
ok, i'll check this:). it sounds good.
also one thing to point out, u should not do all of your stuff in the constructor of your class....,