Home > Software design >  Switching between original condition and SequentialAnimation
Switching between original condition and SequentialAnimation

Time:03-01

Not sure how to express my question. My snippet code is just to illustrate what I want to achieve in a much bigger code base. I have an "originalCondition" that changes the opacity of an image which is independent of the SequentialAnimation. What I want to achieve after the SequentialAnimation has completed changing the opacity for the Image that the "originalCondition" binds back to the opacity. Not sure if bind is the appropriate way to describe it

For some reason, this does not occur and I am not sure why or how to do it.

Item {
    id: root
    property bool activatedLetter: false

    Button {
       text: "Click me"
       onClicked: root.activatedLetter = true
     }
         
    Image {
        id: headerBackgroundImage
        visible: true
        opacity: originalCondition 
    }

    SequentialAnimation {
        running: root.activatedLetter

        onStopped: {
            if(root.activatedLetter) {
                headerBackgroundImage.visible = true
            }
            headerBackgroundImage.opacity = 1
            root.activatedLetter = false
        }

        PauseAnimation {
           duration: 750
        }

        NumberAnimation {
            target: headerBackgroundImage
            property: "opacity"
            from: 1
            to: 0
            duration: 1000
        }

        NumberAnimation {
            target: headerBackgroundImage
            property: "visible"
            from: 1
            to:0
            duration: 1000
        }
    }
}

CodePudding user response:

In your onStopped, instead of this:

headerBackgroundImage.opacity = 1

try this:

headerBackgroundImage.opacity = Qt.binding(() => originalCondition);
  • Related