Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Is there a way to have a state move an object over from adding it's new position after each transition without binding?
Qt 6.11 is out! See what's new in the release blog

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

Scheduled Pinned Locked Moved Solved QML and Qt Quick
2 Posts 1 Posters 853 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    jShu
    wrote on last edited by jShu
    #1

    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?

    1 Reply Last reply
    0
    • J Offline
      J Offline
      jShu
      wrote on last edited by jShu
      #2

      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++});.
      
      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved