Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-85935

QML Item state unexpectedly returns to default state ""

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P1: Critical
    • None
    • 5.15.0
    • None
    • Ubuntu 20.04

    Description

      The states system in QML seems to behave differently in Qt5.15.0 than in previous version.

      Let's say we define 2 states "BLUE" and "GREEN", setting the when property respectively to
      blue and !blue where blue is a boolean property.

       

      import QtQuick 2.15
      import QtQuick.Window 2.15
      
      Window {
          visible: true
          width: 640
          height: 480
      
          Rectangle {
              id: rec
      
              property bool blue: true  
      
              width: 200
              height: 80
              color: "red"
              anchors.centerIn: parent        
             
              onStateChanged: console.log("state =", state) 
             
              states: [
                  State {
                      name: "BLUE"
                      when: rec.blue
                      PropertyChanges {
                          target: rec
                          color: "blue"
                      }
                  },
                  State {
                      name: "GREEN"
                      when: !rec.blue
                      PropertyChanges {
                          target: rec
                          color: "green"
                      }
                  }
              ]
          }    
      
          Timer {
              running: true
              repeat: true
              interval: 1000
              onTriggered: rec.blue = !rec.blue
          }
      }
      

      If you update the blue property from true to false, the item state will change from BLUE to GREEN, but then, if you update it from false to true, the state will first change to default state "" and finally BLUE state.

       

      OUTPUT:
      qml: state = BLUE
      qml: state = GREEN
      qml: state = 
      qml: state = BLUE
      qml: state = GREEN
      qml: state = 
      qml: state = BLUE
      qml: state = GREEN
      

      The return to default state is unexpected and would break a transition between GREEN and BLUE state.

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            qt.team.quick.subscriptions Qt Quick and Widgets Team
            agamet Antoine Gamet
            Votes:
            2 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes