Reputation: 303198
I have a generic QtObject
in QML that I want to animated properties of, and I want to start/stop them all together. I wrote the following code, but Qt Creator errors: qrc:/DummyData.qml:11 Cannot assign to non-existent default property
...where line 11 is the one with ParallelAnimation {
.
import QtQuick 2.5
QtObject {
property real windowFrontLeftOpenPct: 0.0
property real windowFrontRightOpenPct: 0.0
property real windowRearLeftOpenPct: 0.0
property real windowRearRightOpenPct: 0.0
property bool windowAnimationsActive: false
ParallelAnimation {
running: windowAnimationsActive
SequentialAnimation on windowFrontLeftOpenPct {
loops: Animation.Infinite
NumberAnimation { from:0; to:1; duration:2000; easing.type:Easing.InOutSine }
NumberAnimation { from:1; to:0; duration:2000; easing.type:Easing.InOutSine }
}
SequentialAnimation on windowFrontRightOpenPct {
loops: Animation.Infinite
NumberAnimation { from:0; to:1; duration:2000; easing.type:Easing.InOutSine }
NumberAnimation { from:1; to:0; duration:2000; easing.type:Easing.InOutSine }
}
SequentialAnimation on windowRearLeftOpenPct {
loops: Animation.Infinite
NumberAnimation { from:0; to:1; duration:2000; easing.type:Easing.InOutSine }
NumberAnimation { from:1; to:0; duration:2000; easing.type:Easing.InOutSine }
}
SequentialAnimation on windowRearRightOpenPct {
loops: Animation.Infinite
NumberAnimation { from:0; to:1; duration:2000; easing.type:Easing.InOutSine }
NumberAnimation { from:1; to:0; duration:2000; easing.type:Easing.InOutSine }
}
}
}
Can I not mix different target properties in a single parallel animation?
Note: a workaround in this case is to remove the ParallelAnimation
wrapper and apply running:windowAnimationsActive
to each of the SequentialAnimations. However, this is not a generic solution, I think, as it does not allow me to easily pause and resume many animations via a single parent wrapper.
Upvotes: 0
Views: 891
Reputation: 5887
Simply store it in custom property:
QtObject {
id: windowPositions
property real windowFrontLeftOpenPct: 0.0
property real windowFrontRightOpenPct: 0.0
property real windowRearLeftOpenPct: 0.0
property real windowRearRightOpenPct: 0.0
property bool windowAnimationsActive: false
property ParallelAnimation windowAnimations: ParallelAnimation {
running: windowAnimationsActive
SequentialAnimation {
loops: Animation.Infinite
NumberAnimation { target: windowPositions; property: "windowFrontLeftOpenPct"; from:0; to:1; duration:2000; easing.type:Easing.InOutSine }
NumberAnimation { target: windowPositions; property: "windowFrontLeftOpenPct"; from:1; to:0; duration:2000; easing.type:Easing.InOutSine }
}
SequentialAnimation {
loops: Animation.Infinite
NumberAnimation { target: windowPositions; property: "windowFrontRightOpenPct"; from:0; to:1; duration:2000; easing.type:Easing.InOutSine }
NumberAnimation { target: windowPositions; property: "windowFrontRightOpenPct"; from:1; to:0; duration:2000; easing.type:Easing.InOutSine }
}
SequentialAnimation {
loops: Animation.Infinite
NumberAnimation { target: windowPositions; property: "windowRearLeftOpenPct"; from:0; to:1; duration:2000; easing.type:Easing.InOutSine }
NumberAnimation { target: windowPositions; property: "windowRearLeftOpenPct"; from:1; to:0; duration:2000; easing.type:Easing.InOutSine }
}
SequentialAnimation {
loops: Animation.Infinite
NumberAnimation { target: windowPositions; property: "windowRearRightOpenPct"; from:0; to:1; duration:2000; easing.type:Easing.InOutSine }
NumberAnimation { target: windowPositions; property: "windowRearRightOpenPct"; from:1; to:0; duration:2000; easing.type:Easing.InOutSine }
}
}
}
Notice that you cannot use the 'on property' syntax that way. Yo need to specify by target and name. And you could use properties
to change many with one Animation:
QtObject {
id: windowPositions
property real windowFrontLeftOpenPct: 0.0
property real windowFrontRightOpenPct: 0.0
property real windowRearLeftOpenPct: 0.0
property real windowRearRightOpenPct: 0.0
property bool running: false
property SequentialAnimation windowAnimations: SequentialAnimation {
running: windowPositions.running
loops: Animation.Infinite
NumberAnimation { target: windowPositions;
properties: "windowFrontLeftOpenPct,windowFrontRightOpenPct,windowRearLeftOpenPct,windowRearRightOpenPct";
from:0; to:1; duration:2000; easing.type:Easing.InOutSine }
NumberAnimation { target: windowPositions;
properties: "windowFrontLeftOpenPct,windowFrontRightOpenPct,windowRearLeftOpenPct,windowRearRightOpenPct";
from:1; to:0; duration:2000; easing.type:Easing.InOutSine }
}
}
That is just a concept, because creating 4 same properties for same one value is useless as useless is creating the QtObject here, and if you need it somewhere I would call it a bad design.
Upvotes: 3