Load qml state from other file



  • Hi, I want to write qml state in separate files, so I can use the same state and transition in different components
    This is a simple example
    main.qml

    @import QtQuick 1.1

    Rectangle {
    width: 360
    height: 360
    Rectangle {
    id: rect
    width: 60
    height: 60
    x: parent.width/2

        Component.onCompleted: {
            state = "right"
        }
    
        states: [
            RightState{}
        ]
    }
    

    }
    @

    RightState.qml

    @
    import QtQuick 1.1

    State {
    name: "right"
    PropertyChanges {
    target: parent
    x: 500
    }
    }
    @

    the problem is that I don't know how to specify the target of propertyChanges, does anyone know how can do that?



  • I want to create an animation editor, so I need to create some special effects, such as fly in , scale and so on, in order to apply these effects to different items, I want to store states in separate files, so I can assign state to item directly



  • the key point is how to delay setting the target of propertychanges



  • Hello hailong,

    You can use the following code in your RightState.qml :
    @ property Item myItem : theIdOfTheItem
    @
    for each kind of item you want.
    Then in the main.qml, you can set the real myItem you want @states: [
    RightState{
    myItem : Item{...} or theRealId
    }
    ]@
    I haven't done it tought, so please tell me if it works



  • Hi, Thank you very much :) this works

    [quote author="dmcr" date="1352275114"]Hello hailong,

    You can use the following code in your RightState.qml :
    @ property Item myItem : theIdOfTheItem
    @
    for each kind of item you want.
    Then in the main.qml, you can set the real myItem you want @states: [
    RightState{
    myItem : Item{...} or theRealId
    }
    ]@
    I haven't done it tought, so please tell me if it works[/quote]


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.