QML animations visible property changes

前端 未结 6 1236
太阳男子
太阳男子 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条回答
  •  失恋的感觉
    2021-02-13 09:40

    Here is how to do it with opacity:

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

    Keep in mind the advice of Vasco Rinaldo.

提交回复
热议问题