[Qt-qml] Apply Transform to Item in onChildrenChanged?
michael.brasser at nokia.com
michael.brasser at nokia.com
Fri Oct 22 07:42:49 CEST 2010
Hi Charley,
On 22/10/2010, at 9:36 AM, ext Charley Bay wrote:
> I wrote my own "layout" type class by hooking
> into onChildrenChanged which is triggered on
> parent changed, and it works great:
>
> Item {
> id: myItem
> onChildrenChanged: {
> myItem.myUpdateChildrenPlacement()
> }
>
> function myUpdateChildrenPlacement() {
> for(var i= 0; i < myItem.children.length; ++i) {
> myItem.children[i].x = 13;
> myItem.children[i].y = 42;
>
> // HOW TO APPLY A TRANSFORM? LIKE:
> //NOT WORK: myItem.children[i].translate += Rotation { ...}
> }
> }
> }
>
> I know the "translate" is read-only, and that you would
> typically define the Rotation{} when you defined the
> (child) item.
I think you mean "transform" here? The following works for me, using HEAD (if it isn't working for you, it may be that a required fix is coming in 4.7.1):
Rectangle {
id: wrapper
width: 200; height: 200
Rectangle {
id: rect
width: 100; height: 100
color: "green"
anchors.centerIn: parent
}
Rotation {
id: rot
angle: 45
}
Component.onCompleted: {
rect.transform = rot
}
}
However, there isn't any built-in way to *append* to a list property (the rotation would replace any transforms currently on the item). You should be able to use one of the techniques described at http://doc.qt.nokia.com/4.7/qdeclarativedynamicobjects.html to dynamically create a Rotation element for each child.
Just in case you haven't noticed them before, I'll also mention that there are also simple "rotation" and "scale" properties that would be easier to manipulate, assuming you didn't need the full features offered by Rotation, etc.
Regards,
Michael
More information about the Qt-qml
mailing list