Eugeniu Znagovan
Eugeniu Znagovan

Reputation: 519

QGraphicsScene set item scene position

I have a QGraphicsScene that contains a hierarchy of QGraphicsItems. Method item.scenePos() returns the scene coordinates of the item. I'm looking for something like setScenePos() in order to change positions of the items by giving them scene coordinates. How can I achieve this ?

Upvotes: 2

Views: 5163

Answers (1)

eyllanesc
eyllanesc

Reputation: 243887

As the docs says:

QPointF QGraphicsItem::scenePos() const

Returns the item's position in scene coordinates. This is equivalent to calling mapToScene(0, 0).

to get what you want you can do the inverse

# setScenePos(QPointF point)
point = QPointF(xx, yy)
point_item = item.mapFromScene(point)
item.setPos(point_item)

Upvotes: 2

Related Questions