Setting and clearing anchors from javascript
-
wrote on 14 Aug 2011, 21:50 last edited by
I am trying to figure out how to set and clear the anchors of components from javascript.
I am doing this because I need to clear anchors when a component is pressed to allow dragging, and then reset the anchor to it's previous value after it is released. Could someone help me with this issue please?P.S. If anyone wonders why I need to do this, I am creating a transform control similar to the one in photoshop that allows you to scale, rotate, and move layers.
-
wrote on 15 Aug 2011, 01:21 last edited by
Hi,
Setting an anchor to undefined will clear it.
You might also want to play around with using the "AnchorChanges":http://doc.qt.nokia.com/4.7-snapshot/qml-anchorchanges.html element, as it will automatically handle restoring anchors for you.
Regards,
Michael -
wrote on 15 Aug 2011, 03:11 last edited by
I hadn't come across the AnchorChanges element that seems like a better approach. I did, however, see the setting of the anchor to undefined, but how do I set the anchor to this value within a javascript file? undefined is not defined in js, no pun intended :).
-
wrote on 17 Aug 2011, 01:43 last edited by
Hi,
undefined is actually a property of the global object (see e.g. http://www.diveintojavascript.com/core-javascript-reference/the-undefined-property), so you should be able to do the following, for example:
@obj.anchors.left = undefined@
(where obj is the Item you are removing the left anchor from).
Regards,
Michael -
wrote on 17 Aug 2011, 04:33 last edited by
Oh ok I understand now. undefined is always available in javascript in the global scope. I seem to remember reading somewhere that you could not access variable in the global scope from js, but I guess that this is not true for the undefined variable. Thanks for your help, I got working!
1/5