Is there a way to have a state move an object over from adding it's new position after each transition without binding?



  • I have an object that I want to move from it's new position every time that particular state is set. I've tried making a separate property called xPos which is set by the object's new position of x after the transition is finished inside onRunningChanged, then entering a default state just to be able to switch back to the state to move x again since calling the same state does nothing but it doesn't seem to work. I'm also using the extra variable because using x causes a runtime binding loop error.

    Here is my code:

    property int xPos: 0

    states: [
    State {
    name: "nextStep"
    PropertyChanges {
    target: progressBar_Id
    x: -1*(progressBar_Id.step.width) + xPos
    }
    },
    State {
    name: "previousStep"
    PropertyChanges {
    target: progressBar_Id
    x: progressBar_Id.step.width + xPos
    }
    },
    State {
    name: "default"
    PropertyChanges {
    target: progressBar_Id
    x: xPos
    }
    }
    ]

    transitions: [
        Transition {
            from: "*"
            to: "nextStep"
            NumberAnimation {properties: "x"; easing.type: Easing.Linear; duration: 1000}
            onRunningChanged: {
                if(!running) {
                    xPos = progressBar_Id.x;
                    console.info("xPos= " + xPos);
                    state = "default";
                }
            }
        },
        Transition {
            from: "*"
            to: "previousStep"
            NumberAnimation {properties: "x"; easing.type: Easing.Linear; duration: 1000}
        }
    ]
    

    xPos seems to get set from the console output but never applies the new xCoord to the object. Also by the way, how do I get the code to format correctly in this Qt Forum, the Transitions are in the same spot as State, what gives?



  • Actually came up with a much better alternative using a ListView.

    ListView {
    id: listView_Id
    width: contentWidth
    height: bubbleSize
    anchors.centerIn: parent
    layoutDirection: Qt.RightToLeft
    orientation: ListView.Horizontal
    spacing: 0
    
    delegate: Item {
        width: bubbleSize
        height: width
    
        ProgressBubble {
            stateText: stateNumber
        }
    }
    model: ListModel { id: progressModel_Id }
    }
    

    Another qml file:

    progressModel.insert(0, {stateNumber: number++});.

Log in to reply
 

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