Calculate scene coordinates from QGraphicsLinearLayout
In my application I used custom objects which derive from QGraphicsWidget and I put them inside QGraphicsLinearLayout. But now I need to find scene co开发者_StackOverflow社区ordinates of each item. Is it possible? How?
QGraphicsWidget
inherits from QGraphicsObject
which in turn inherits from QGraphicsItem
. So you can use one of the mapToScene
function to convert item coordinates to the scene ones.
For example:
QPointF p = myItem->mapToScene(QPointF(0,0));
will give you the scene location of the top left corner of the item.
Use this method from QGraphicsItem which is a base of QGraphicsWidget:
myItem->scenePos()
精彩评论