C
デフォルト状態の制限
Qt Quick Ultralite のデフォルト状態は固定されており、QML オブジェクトが定義されている同じ QML ファイルで定義されているプロパティバインディングのみを含んでいます。しかし、Qt Quick のデフォルト状態は、コンポーネントの現在のプロパティとその値のスナップショットです。このスナップショットは、別の状態からデフォルトの状態に戻ると復元されます。
// MyItem.qml Button { id: root states: [State { name: "state1"; PropertyChanges { target: root; x: 15 } }] x: 5 // defines the default state value onClicked: { root.x = 10 root.state = "state1" // x changes to 15 root.state = "" // x changes to 5, not to 10 } } // Other.qml MyItem { x: 11 // does not change the default state value of x to 5 }
回避策
オブジェクトのプロパティをローカルで宣言されたプロパティにバインドして、カスタマイズ可能なデフォルト状態を作成することで、この制限を回避することができます:
// MyItem.qml Text { property string defaultText: "default state" text: defaultText // this generates a binding which is then used by the \l {qmltocpp} to generate a default state ... } // Other.qml MyItem { defaultText: "new default state" // MyItem displays this text instead of "default state" when swtiching to the default state }