Thank you for your reply. I find out why the two codes are running the same
result. Besides, I also find something that I do not know if it is a bug.
First, the both codes behave the same result because the rectangles' ids are
wrong. In the pdf file, it says the ids are stop_light and go_light. But in
the example file, they turn to be stopLight and goLight. So, when I paste
the code from pdf to the example code, the "target: stop_light" refers to no
one. But the qmlviewer ignores this and puts the target to the both
Rectangles which have the color property. I do not know if this is what the
qmlviewer should be, if not, this should be filed as a bug of qmlviewer.
Second, as we know that if we refer to no one in target property, and the
qmlviewer will apply the target to all that have the color property. Then we
need not to write the target property if we want this feature. the below two
codes will have the same result.
code one
> transitions: [
> Transition {
> from: "*"; to: "*"
> PropertyAnimation {
> target: stopLight
> properties: "color"; duration: 1000
> }
> PropertyAnimation {
> target: goLight
> properties: "color"; duration: 1000
> }
> } ]
code two
> transitions: [
> Transition {
> from: "*"; to: "*"
> PropertyAnimation {
>
> properties: "color"; duration: 1000
> }
> PropertyAnimation {
>
> properties: "color"; duration: 1000
> }
> } ]
Also, the pdf and example that I mentioned are here.
http://qt.nokia.com/developer/learning/online/training/materials/qt-essentials-qt-quick-edition
Chapter is
States and Transitions
Download the presentation slides
(pdf)<http://get.qt.nokia.com/training/QtQuickforCppDevelopers/slides/qml-states-transitions.pdf>
Download the code
examples<http://get.qt.nokia.com/training/QtQuickforCppDevelopers/addons/addon-qml-states-transitions.zip>
Maybe someone could contacts the writer to revise the pdf or the example.
Owen
2011/4/26 <[email protected]>
> They actually turn on (red/blue) immediately. Only when the reversible is
> set it will be the same.
>
>
>
> --Kuifei
>
>
>
> import QtQuick 1.0
>
> Rectangle {
>
> width: 150; height: 250
>
> Rectangle {
>
> id: stopLight
>
> x: 25; y: 15; width: 100; height: 100
>
> }
>
> Rectangle {
>
> id: goLight
>
> x: 25; y: 135; width: 100; height: 100
>
> }
>
> states: [
>
> State {
>
> name: "stop"
>
> PropertyChanges { target: stopLight; color: "red" }
>
> PropertyChanges { target: goLight; color: "black" }
>
> },
>
> State {
>
> name: "go"
>
> PropertyChanges { target: stopLight; color: "black" }
>
> PropertyChanges { target: goLight; color: "green" }
>
> }
>
> ]
>
> MouseArea {
>
> anchors.fill: parent
>
> onClicked: parent.state == "stop" ?
>
> parent.state = "go" : parent.state = "stop"
>
> }
>
> // transitions: [
>
> // Transition {
>
> // from: "*"; to: "*"
>
> // PropertyAnimation {
>
> // target: stopLight
>
> // properties: "color"; duration: 5000
>
> // }
>
> // PropertyAnimation {
>
> // target: goLight
>
> // properties: "color"; duration: 5000
>
> // }
>
> // } ]
>
> transitions: [
>
> Transition {
>
> from: "stop"; to: "go"
>
> reversible: true
>
> PropertyAnimation {
>
> target: stopLight
>
> properties: "color"; duration: 5000
>
> }
>
> },
>
> Transition {
>
> from: "go"; to: "stop"
>
> reversible: true
>
> PropertyAnimation {
>
> target: goLight
>
> properties: "color"; duration: 5000
>
> }
>
> }
>
> ]
>
> }
>
>
>
>
>
> *From:* [email protected] [mailto:
> [email protected]] *On Behalf Of *ext Owen
> Zhao
> *Sent:* 2011年4月26日 9:56
> *To:* [email protected]
> *Subject:* [Qt-qml] The two transitions have the same result. But I think
> it shouldn't.
>
>
>
> Hi all,
> I am learning the Qt Essentials(QML Version) by myself. And something in
> transitions is confusing me.
> In the pdf I download from nokia website, it says.
>
> transitions: [
> Transition {
> from: "stop"; to: "go"
> PropertyAnimation {
> target: stop_light
> properties: "color"; duration: 1000
> }
> },
> Transition {
> from: "go"; to: "stop"
> PropertyAnimation {
> target: go_light
> properties: "color"; duration: 1000
> }
> } ]
>
> is the same as
>
> transitions: [
> Transition {
> from: "*"; to: "*"
> PropertyAnimation {
> target: stop_light
> properties: "color"; duration: 1000
> }
> PropertyAnimation {
> target: go_light
> properties: "color"; duration: 1000
> }
> } ]
>
> And when I run the code in qmlviewer, they do do the same thing.(full code
> is provided at the bottom of this email) However, I believe they shouldn't
> be the same. As in the first code when transitioning from the "stop" to "go"
> state, the target is only the "stop_light", and in the second code when
> transition accurs, both the "stop_light" and "go_light" are targets.
>
> Am I wrong or there is something I misunderstood?
>
> The full qml file code here:
>
> import QtQuick 1.0
>
> Rectangle {
> width: 150; height: 250
>
> Rectangle {
> id: stopLight
> x: 25; y: 15; width: 100; height: 100
> }
> Rectangle {
> id: goLight
> x: 25; y: 135; width: 100; height: 100
> }
>
> states: [
> State {
> name: "stop"
> PropertyChanges { target: stopLight; color: "red" }
> PropertyChanges { target: goLight; color: "black" }
> },
> State {
> name: "go"
> PropertyChanges { target: stopLight; color: "black" }
> PropertyChanges { target: goLight; color: "green" }
> }
> ]
>
> state: "stop"
>
> MouseArea {
> anchors.fill: parent
> onClicked: parent.state == "stop" ?
> parent.state = "go" : parent.state = "stop"
> }
>
> transitions: [
> Transition {
> from: "*"; to: "*"
> PropertyAnimation {
> target: stopLight
> properties: "color"; duration: 1000
> }
> PropertyAnimation {
> target: goLight
> properties: "color"; duration: 1000
> }
> } ]
>
>
> }
>
> --
> Owen Zhao
>
--
肇鑫
Owen Zhao
tel/miliao:18602412580
qq:66975918
msn:[email protected]
_______________________________________________
Qt-qml mailing list
[email protected]
http://lists.qt.nokia.com/mailman/listinfo/qt-qml