How can I avoid creating a property binding on initialization in QML?

后端 未结 4 802
野的像风
野的像风 2021-01-17 11:36

I want to create a custom QML component with two properties one and two, which should have default values when left uninitialized. In particular, i

4条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-17 12:16

    Explicitly break the binding upon component completion:

    Rectangle {
        property int one: 1
        property int two: 2 * one
        Component.onCompleted: two = two
    }
    

    The two = two assignment breaks the binding and two is no longer updated as one changes.

提交回复
热议问题