[Interest] How can i animate Layout.preferredWidth and friends?

Saether Jan-Arve Jan-Arve.Saether at digia.com
Fri Oct 11 14:37:04 CEST 2013


> > Of course it should not crash.
> > I get an ASSERT: "mo" in file qml\qqmlvme.cpp, line 849 (this is with current stable branch though).
>> > I'm a bit curious to know why do you want to animate that property?
> > What do you want to achieve?
>> > Jan Arve
>> > From: interest-bounces+jan-arve.saether=digia.com at qt-project.org [mailto:interest-bounces+jan-arve.saether=digia.com at qt-project.org] On Behalf Of Mark
> > > Sent: 30. september 2013 01:40
> > > To: Qt Interest
> > > Subject: [Interest] How can i animate Layout.preferredWidth and friends?
> > > 
> > > Hi,
> > > 
> > > I thought something as simple as:
> > > 
> > >            Behavior on Layout.preferredWidth {
> > >                NumberAnimation { duration: 1000 }
> > >            }
> > > 
> > > would do.. Apparently not since it crashes qmlscene..
> > > Do i need to do it differently or did i just hit a bug?
> > > 
> > > Version details:
> > > Qt 5.1.0 x64 (i know, 5.1.1 is out)
> > > Mac Mountain Lion fully updated
> > > 
> > > Cheers,
> > > Mark
>  Hi Jan,
>
> What i try to do is animate the (in this case) width. In a simple 
> description that would be it. However, i try to animate the with of a
> component that is within a Layout. In this case a RowLayout. If i use
> the width, the RowLayout itself doesn't update, you can see that in
> this snippet [1]. Just press the nice orange square :) What i want
> for that is to work. I tried animating the Layout.preferredWidth
> property because changing the width using that does update the
> RowLayout, but then the animation doesn't work.
>
> That's all i'm trying to do.
>
> [1] http://pastebin.kde.org/pxgjxhtza

Your example code works exactly how I would expect it to work.
You are only animating the width of the red rectangle, and the layout
doesn't rely on the width property for rearranging its items. 
Therefore, the layout and the other children are not affected by this.
(Try to set opacity: 0.5 on the green item, then you will better see 
what's going on :-)

However, I would expect changing togglePreferredWidth to actually
toggle Layout.preferredWidth (while keeping the Behavior on width) to
do what you want, but I think that Behaviors are only applied if the property
is changed in QML. (The width property is changed in the C++ backend of
the layout engine, which then wouldn't apply the behavior)

This modified example demonstrates the issue, and AFAIK it's a limitation of the
Behavior element:

http://pastebin.com/bcD9wRu5

Jan Arve




More information about the Interest mailing list