QML animations visible property changes

前端 未结 6 1260
太阳男子
太阳男子 2021-02-13 08:52

I want an animation to be painted when an element becomes visible (is should appear smoothly, not the whole at all)

I tried this

states: State
{
    name         


        
6条回答
  •  Happy的楠姐
    2021-02-13 09:47

    I had to modify Uga Buga's answer slightly to make it work, here's what I got:

    Rectangle {
        id: myRect
        property bool stateVisible: true
                ...
        states: [
            State { when: myRect.stateVisible; 
                    PropertyChanges {   target: myRect; opacity: 1.0    }},
            State { when: !myRect.stateVisible;
                    PropertyChanges {   target: myRect; opacity: 0.0    }}
        ]
        transitions: [ Transition { NumberAnimation { property: "opacity"; duration: 500}} ]
    }
    

    Please note that stateVisible is referenced through item id, it doesn't work without it on my system. Maybe some change in API caused this.

    I also added square bracket in transitions field as an array is required there (although QML syntax seems to allow spelling without brackets)

提交回复
热议问题