Default state limitations

The default state in Qt Quick Ultralite is fixed, containing only the property bindings defined in the same QML file where the QML object is defined. However, the default state in Qt Quick is a snapshot of the component's current properties and their value. This snapshot is restored when switching back to the default state from another state.

// 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
}
							

Workaround

You can workaround this limitation by binding an object's property to a locally declared property to create customizable default state:

// 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
}