[Interest] How to change parent of scaled QGraphicsItem while retaining scene bounding rect?

Christian Gagneraud chgans at gmail.com
Wed Aug 8 07:05:09 CEST 2018


On 8 August 2018 at 15:49, Patrick Stinson <patrickkidd at gmail.com> wrote:
> Thanks for the reply. I am just particularly dense in this sort of cognitive operation (something about flipping symbolic representations like in fractional arithmetic) and might do well with just a bit of code or pseudo code. Do you think you might provide some?

I haven't done graphics stuff in a while (unfortunately), but this
should be as simple as:
scene_xform = item->sceneTransform();
local_xform = next_parent->sceneTransform().inverted() * scene_xform;
item.setTransform(local_xform);
item.setScale(1.0);
item.setRotation(0.0);
item.setParentItem(next_parent);

AFAIR, QGI's rotation and scale need to be reset b/c they are combined
with QGI's transform()

Hope this help!
Chris

>
> Thanks!
>
>> On Aug 7, 2018, at 6:24 PM, Christian Gagneraud <chgans at gmail.com> wrote:
>>
>> On 8 August 2018 at 11:08, Patrick Stinson <patrickkidd at gmail.com> wrote:
>>> Hello!
>>>
>>> I am trying to change the parent of a QGraphicsItem without it appearing to move or change size on the scene. Both the item, old parent, and new have arbitrary scale values set. How can this be done?
>>
>> If you grab the item's sceneTransform() before re-parenting, you
>> should be able to deduce it's new local transform from it's new parent
>> sceneTransform().
>>
>>
>>>
>>> Thanks!
>>> _______________________________________________
>>> Interest mailing list
>>> Interest at qt-project.org
>>> http://lists.qt-project.org/mailman/listinfo/interest
>



More information about the Interest mailing list