QGraphicsItem, location of 2 items in each other local space
-
Hey
I'm getting lost with all the mapToScene/mapFromScene...
Say I have 2 QGraphicsItems, 1 of them located at
itmA :
xy 25 ,0itmB :
xy 100,100if I want to get a local location of itmB while being in itmA... how can I do it? They are not child/parent connected. I think the answer would be 75,100 but how do I get to that number from inside pin by just having itmB pointer...
mapFromScene(mapToScene(itmB->pos()));
?TIA
-
Hi,
Can you explain what you are trying to achieve with that information ?
-
@SGaist said in QGraphicsItem, location of 2 items in each other local space:
Hi,
Can you explain what you are trying to achieve with that information ?
I'm drawing some items and some of them needs to know the location of another item in their local space to move rect boxes around properly.
One purpose would be like connection pins for a entry node. It would need to know its parent location - as its parent is fine, but sub children would not be parented to main node but to parent child and thus I would need position of parent translated to a random node to properly draw it.
-
Something like shown in the Elastic Nodes example ?
-
@SGaist Possibly yes... I'm back to this & lost again... I think I figured out the last problem without needing it, but now I need it again...
Scenario = bezier curve, 4 points, first start, control left, control right, endpoints.Start and end can never cross each other on Z-axis.
Control left can not pass end on the Z-axis and control Right can not pass start on z-axis either.
Control points are children of start/endpoints.(Hope this make sense...)
So what I need to find out is... location of End point while being inside Control Left event. I need to somehow map scenePos() of End point to my Control Left local space....
here is some debuging I was trying to do...
(test case, moving right control point towards left Start item)
targetPos : QPointF(348,-478) // scenePos() of Start item myPos : QPointF(336,-617) // scenePos() of rightControl scenePos() - already invalid position because we passed the Z location of targetPos item. myLocPos : QPointF(-237,2) This should match other item loc at some point... localPos of rightControl mapFromScene: QPointF(12,139) // mappings mapToItem : QPointF(113,-477) // mappings mapFromItem : QPointF(583,-479) // mappings
one of mappings should return a number close to myLocPos but none of them do :- (
Debug code :
qDebug() << "oh snap!" << "\n targetPos : " << itemPos << "\n myPos : " << myPos << "\n myLocPos : " << newPos << "local pos of rightControl item" << "\n mapFromScene: " << mapFromScene(itemPos) << "\n mapToItem : " << mapToItem(items[x], itemPos) << "\n mapFromItem : " << mapFromItem(items[x], itemPos);
Esentially this :
Top left item, is the myPos/newPos variable newPos being local and myPos being scenePos(), item below is the "Start"