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. Issue with State Transitions
Forum Updated to NodeBB v4.3 + New Features

Issue with State Transitions

Scheduled Pinned Locked Moved Solved QML and Qt Quick
2 Posts 1 Posters 625 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.
  • P Offline
    P Offline
    Placeable
    wrote on last edited by kshegunov
    #1

    In my QML I have the following markup for 2 states & transition that are supposed to expand a rectangle when clicking a toggle button. It only works when expanding the rectangle every time just fine but not when the rectangle goes back to its "original" state (back to textIn), then it just snaps to the values without a transition. What gives?

    ...
    
    property int animTargetY: 0
    
    Rectangle {
        id: parentContainer
        width:  parent.width
        height: parent.height
        color: model.bgColor
        state: "textIn"
    
        /* Animations for ParentContainer */
        states: [
            State {
                name: "textOut"
                PropertyChanges {
                    target: parentContainer
                    y: -animTargetY
                    height: parentContainer.parent.height + animTargetY
                }
            },
            State {
                name: "textIn"
                PropertyChanges {
                    target: parentContainer
                    y: 0
                    height: parentContainer.parent.height
                }
            }
        ]
        transitions: [
            Transition {
                from: "textIn"
                to: "textOut"
                NumberAnimation { target: parentContainer; properties: "y,height"; easing.type: Easing.OutExpo; duration: 500 }
            },
            Transition {
                from: "textOut"
                to: "textIn"
                NumberAnimation { target: parentContainer; properties: "y,height"; easing.type: Easing.InExpo; duration: 500; }
            }
        ]
    }
    
    Rectangle {
        color: "#FFFFFF"
        width: 150
        height 50
    
        MouseArea {
            anchors.fill: parent
            onClicked: {
                var diff = (textContainer.height - solutionTextRect.height) + 10;
                animTargetY = diff;
                parentContainer.state = parentContainer.state == 'textOut' ? 'textIn' : 'textOut';
                console.log("Current State: " + parentContainer.state);
            }
        }
    }
    

    [Moved to Qt Quick ~kshegunov]

    1 Reply Last reply
    0
    • P Offline
      P Offline
      Placeable
      wrote on last edited by
      #2

      Found out that as soon as I animated the height with Transition it would just snap instantly, dunno why. But I changed the QML to this, using Behaviors instead and now it works:

       states: [
          State {
              name: "textOut"
              PropertyChanges {
                  target: parentContainer
                  y: -animTargetY
                  height: parentContainer.parent.height + animTargetY
              }
          }
      ]
      Behavior on height {
         NumberAnimation { easing.type: Easing.InOutQuad; duration: 400 }
      }
      
      Behavior on y {
         NumberAnimation { easing.type: Easing.InOutQuad; duration: 400 }
      }
      
      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