[Interest] Aligning objects in QGraphics....

BRM bm_witness at yahoo.com
Thu Aug 9 17:55:38 CEST 2012

> From: BRM <bm_witness at yahoo.com>

>I have three custom QGraphicsWidgets. Two of them belong to a custom layout that is assigned to the third:
>  - custom layout
>       - widget2
>       - widget3
>I am trying to move widget2 to overlay widget3 at specific coordinates; however, the results are a bit confusing.
> Widget3 has a signal to notify widget2 of the coordinates it is to align two. Both sets are converted to Scene
> Coordinates before being emitted via the signal:
Q_EMIT coordinateNotifier(mapToScene(coordinate);
>This is then received by the widget2 which converts it to local coordinates:
>storedCoordinate = mapFromScene(remoteCoordinate);
>And then calls a reposition which converts it to Parent coordinates:
>QPointF origin = mapToParent(storedCoordinate);
>It then sets its position to this new coordinate:
>However, everytime it sets its position, the overlay widget moves increasingly farther away from where it should be. Kind of random in where it goes, but kind of not in that is does mostly the same thing every time.

Namely for the e-mail archives....but found my own dumb bug - I got it correct above, but had a mapFromParent() on the origin which made it go all over the place.
While the inconsistency was still not quite expected, it is nice as it showed a glaring issue right up front. (It would have been quite a pain finding it otherwise.)

Tired vs Fresh minds...


More information about the Interest mailing list