Item property changes defined in multiple places?
-
I'd like to define a reusable component that is controlled with states.
I can set property changes for each state and that works just fine.If I create objects that use my new component is there a way to define additional property changes when the state is changed?
Example
The reusable "Page" item defined in Page.qml:
@Item
{
id: root
states:
[
State
{
name: "Hide"
PropertyChanges { target: root; x: width * 2; visible: false }
},
State
{
name: "Show"
PropertyChanges { target: root; x: 0; visible: true }
}
]
}
@An item that uses the Page item:
@Page
{
states:
[
State
{
name: "Hide"
PropertyChanges { target: textBubble; state: "hide" }
},
State
{
name: "Show"
PropertyChanges { target: textBubble; state: "show"; text: qsTr("Touch (or swipe) when you’re ready to move to the next section") }
}
]
}@
The property changes defined in Page.qml work but the changes defined elsewhere don't.
No messages are printed to the debugging log.Any suggestions?
-
I think if you create an object of your QML file and add custom states they will be added to the same object (same states list), so it will work if you use different names and not "Hide" in your Page.qml and also a state with the same name in the external object, since you can't have 2 states with the same name.
You need to be careful with this, because as you might know only 1 state can be active at the same time, so if you add states to the same object you might get unexpected results.
If you can don't add the internal states to the root Item, so if you add additional states from the outside your have no conflicts like that, that is how I do it at least. -
I'm trying to add additional "PropertyChanges" to existing states. (When the page is shown I'd like to have additional animations triggered). I hoped I could put all the common functions into an inheritable object instead of repeating them on every page.
I thought about trying to append a PropertyChange object to the existing "state object's changes property":http://qt-project.org/doc/qt-4.8/qml-state.html#changes-prop but it looks like it's read only.
I might be able to trigger actions in the child objects using the when clause.
Thanks for the help