Animation on event [solved]



  • I want to fire off a ColorAnimation upon an event (onTextChanged) but couldn't find an example of how to accomplish this.

    Can you hint me into the right direction?



  • "Here":http://doc.qt.nokia.com/latest/qml-behavior.html

    I think that's what you need, play around with Behavior on text property.



  • This doesn't seem to help me much since I want to change the color-property of a TextEdit once the text-property changes. Behaviours can only be assigned to the same property.

    The following example doesn't work b/c of the on color in ColorAnimation

    @ Behavior on text {
    ColorAnimation on color { from: "yellow"; duration: 1000 }
    }@

    EDIT: With state-changes it works at least once. I want the text turn every time it changes from red to black.
    Changing the state to something else upon completion of the animation (onCompleted) doesn't seem to work at all.

    So what am I supposed to do?

    @ TextEdit {
    id: txtCurrentTrack
    text: "trololol"
    onTextChanged: txtCurrentTrack.state = 'changed'

                    states: [
                        State {
                            name: "changed"
                            PropertyChanges { target: txtCurrentTrack; color: "black" }
                        },
    
                        State {
                            name: "finished"
                            PropertyChanges { target: txtCurrentTrack; color: "grey" }
                        }
                     ]
    
                    transitions: Transition {
                        ColorAnimation {  from: "red"; to: "black"; duration: 1000; onCompleted: txtCurrentTrack.state = "finished"   }
    
                         }
    
                }@


  • Hello, try this:

    @TextEdit {
    id: text_edit1
    x: 117
    y: 62
    width: 80
    height: 20
    text: "textEdit"

        onTextChanged: { colAnim.start(); }
    
        PropertyAnimation {
            id: colAnim
            target: text_edit1
            property: "color"
            from: "red"
            to: "blue";
            duration: 1000
            running: false
        }
    
    }@


  • awesome, it works like a charm.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.