And here is a corrected version (with a diff). Let me know if it works now.
On 20 April 2010 11:06, Gianni Valdambrini <[email protected]> wrote: > Hi all, > I wrote a custom element that looks like a text element with a slide > effect on the text change. > The problem is in the transition. The element works in this way: > there are 2 text elements, one placed on the left and the other on the > right of the element. The latter has the same left and right anchor in > order to hide the element. > When the text changes the transition expands the text on the right > changing its left anchor and shrinks the left one. > Everything seems to work fine if I disable the transition, with the text > on the right not visibile. Using the old version of Qml from Qt Creator Qml > 1.3.8 everything works fine even with transition enable (replacing > "properties" with "matchProperties" and the easing syntax), so I cannot > figure out what is wrong with this code. > Any help is appreciated. > > Thanks, > Gianni > > > import Qt 4.7 > > Rectangle { > id: slidetext > property string text: "" > property int duration: 2000 > property string easing: "Linear" > property string horizontalAlignment: "AlignLeft" > property string verticalAlignment: "AlignTop" > > Text { > id: text1 > anchors.left: parent.left > anchors.right: parent.right > anchors.top: parent.top > anchors.bottom: parent.bottom > text: "" > text: { > if (parent.state == "" || parent.state == "State1") > text > else > parent.text > } > horizontalAlignment: parent.horizontalAlignment > verticalAlignment: parent.verticalAlignment > } > > Text { > id: text2 > anchors.left: parent.right > anchors.right: parent.right > anchors.top: parent.top > anchors.bottom: parent.bottom > text: "" > text: { > if (parent.state == "State2" || parent.state == > "State3") > text > else > parent.text > } > horizontalAlignment: parent.horizontalAlignment > verticalAlignment: parent.verticalAlignment > } > > Item { > id: privateProps > property bool isSliding: false > } > > text: Behavior { > enabled: !privateProps.isSliding > PropertyAction { target: slidetext; property: "state"; > value: { > if (state == "") > "State1" > else > "State3" > } > } > } > > states: [ > State { > AnchorChanges { target: text1; right: > slidetext.left; } > AnchorChanges { target: text2; left: slidetext.left; > } > PropertyChanges { target: privateProps; isSliding: > true } > name: "State1" > }, > State { > AnchorChanges { target: text1; left: > slidetext.right; right: slidetext.right; } > AnchorChanges { target: text2; left: slidetext.left; > right: slidetext.right; } > PropertyChanges { target: privateProps; isSliding: > false } > name: "State2" > }, > State { > AnchorChanges { target: text1; left: slidetext.left; > } > AnchorChanges { target: text2; right: > slidetext.left; } > PropertyChanges { target: privateProps; isSliding: > true } > name: "State3" > } > ] > transitions: [ > Transition { > from: ""; to: "State1" > SequentialAnimation { > NumberAnimation { properties: "x,width"; > easing.type: slidetext.easing; > duration: slidetext.duration; } > PropertyAction { target: slidetext; > property: "state"; value: "State2"; } > } > }, > Transition { > from: "State2"; to: "State3" > SequentialAnimation { > NumberAnimation { properties: "x,width"; > easing.type: slidetext.easing; > duration: slidetext.duration; } > PropertyAction { target: slidetext; > property: "state"; value: ""; } > } > } > ] > } > > > _______________________________________________ > Qt-qml mailing list > [email protected] > http://lists.trolltech.com/mailman/listinfo/qt-qml > > -- Ivan De Marino | Software Engineer | France Telecom R&D UK - Orange Labs w. +44 20 8849 5806 | m. +44 7515 955 861 | m. +44 7974 156 216 ivan[dot]demarino[at]orange-ftgroup.com | ivan[dot]de[dot]marino[at]gmail[dot]com www.detronizator.org | www.linkedin.com/in/ivandemarino
SlidingText-correct.qml
Description: Binary data
17,23c17
< text: ""
< text: {
< if (parent.state == "" || parent.state == "State1")
< text
< else
< parent.text
< }
---
> text: (parent.state == "" || parent.state == "State1") ? "" : parent.text
34,40c28
< text: ""
< text: {
< if (parent.state == "State2" || parent.state == "State3")
< text
< else
< parent.text
< }
---
> text: (parent.state == "State2" || parent.state == "State3") ? "" : parent.text
50c38
< text: Behavior {
---
> Behavior on text {
63,64c51,52
< AnchorChanges { target: text1; right: slidetext.left; }
< AnchorChanges { target: text2; left: slidetext.left; }
---
> AnchorChanges { target: text1; anchors.right: slidetext.left; }
> AnchorChanges { target: text2; anchors.left: slidetext.left; }
69,70c57,58
< AnchorChanges { target: text1; left: slidetext.right; right: slidetext.right; }
< AnchorChanges { target: text2; left: slidetext.left; right: slidetext.right; }
---
> AnchorChanges { target: text1; anchors.left: slidetext.right; anchors.right: slidetext.right; }
> AnchorChanges { target: text2; anchors.left: slidetext.left; anchors.right: slidetext.right; }
75,76c63,64
< AnchorChanges { target: text1; left: slidetext.left; }
< AnchorChanges { target: text2; right: slidetext.left; }
---
> AnchorChanges { target: text1; anchors.left: slidetext.left; }
> AnchorChanges { target: text2; anchors.right: slidetext.left; }
_______________________________________________ Qt-qml mailing list [email protected] http://lists.trolltech.com/mailman/listinfo/qt-qml
