[Qt-qml] Apply Transform to Item in onChildrenChanged?
Charley Bay
charleyb123 at gmail.com
Fri Oct 22 18:51:19 CEST 2010
Hi, Michael--
>>Charley spaketh:
>> 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.
Michael respondeth:
> 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):
> <snip, code that works>
Oh, thanks! Your code works for me: Yes, I meant
"transform", and I didn't actually attempt to *overwrite*
the value because the docs seemed to suggest it was
read-only:
<http://doc.qt.nokia.com/4.7/qml-item.html#transform-prop>
...Are the docs incorrect, or am I reading them
improperly? (I find the "read-only" moniker to be
quite helpful on all the property documentation
to which it applies. For example, you'll notice
the "Item.transformOrigin" below it is *not* read only,
so I know I can overwrite it directly.)
> However, there isn't any built-in way to *append* to
> a list property (the rotation would replace any
> transforms currently on the item).
Thanks -- actually, your example works for me as-is,
I currently just want to overwrite anyway. (If you
forced me to think about the problem, I'm not sure
if it's appropriate to *append* transforms at all
from within MyNewLayoutElement -- I probably
should think about that.)
> 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.
Ah! Good reading. I need to read that again.
> 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.
Very good point -- thanks. In this case, I'm actually
animating "angle" around the Y-axis, so I needed
the Rotation {}.
Thanks very much for your help! (I think I'm starting
to get the hang of this QML thing.)
--charley
More information about the Qt-qml
mailing list