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

Property bindings produce wrong values for Animation.to

    XMLWordPrintable

Details

    • 0e69268b4 (dev), b2c09fd75 (6.6), 3f862f736 (6.5)

    Description

      Code

      import QtQuick 2.15
      import QtQuick.Window 2.15
      
      Window {
          width: 400
          height: 300
          visible: true
          id: window
      
          Text { text: `Coordinates: (${pt.x.toFixed(2)}, ${pt.y.toFixed(2)})` }
      
          Rectangle {
              id: line
              anchors.centerIn: parent
              width: parent.width // WORKAROUND: Replace with `width: window.width`
              height: 2
              color: "blue"
          }
      
          Rectangle {
              id: pt
              anchors.verticalCenter: line.verticalCenter
              height: line.height*5
              width: height
              color: line.color
              radius: height/2
              SequentialAnimation { // PARTIAL WORKAROUND: Remove the outer SequentialAnimation; make the NumberAnimation loop indefinitely
                  running: true
                  loops: Animation.Infinite
                  NumberAnimation {
                      id: anim
                      target: pt
                      property: "x"
                      from: 0
                      to: line.width-pt.width // WORKAROUND: Replace with `to: window.width-pt.width`
                      duration: 1000
                  }
              }
          }
      
          Component.onCompleted: {
              console.log("window.width =", window.width)
              console.log("line.width =", line.width)
              console.log("pt.width =", pt.width)
              console.log("anim.to =", anim.to) // This always prints the correct value
          }
      }
      

       

      Outputs

      All tested versions printed this output (correct):

      qml: window.width = 400
      qml: line.width = 400
      qml: pt.width = 10
      qml: anim.to = 390
      

       

      Expected behaviour (5.15.12/6.2.7 on Windows)

      The blue dot moves across the whole window from left to right repeatedly (x-coordinates go from 0 to 390)

       

      Actual behaviour (Qt 6.3.2 and newer on Windows; all versions on Ubuntu)

      The blue dot creeps along the left edge of the screen repeatedly (x-coordinates go from 0 to -10)

       

      Workarounds

      • In line, replace `width: parent.width` with `width: window.width`, OR
      • In anim, replace `to: line.width-pt.width` with `to: window.width-pt.width`

       

      Partial workaround

      Remove the outer SequentialAnimation and make the NumberAnimation loop indefinitely:

      NumberAnimation {
          id: anim
          running: true
          loops: Animation.Infinite
          target: pt
          property: "x"
          from: 0
          to: line.width-pt.width
          duration: 1000
      }
      

      With this code, the first loop iteration animates from 0 to -10 (wrong), but all subsequent iterations animate from 0 to 390 (correct)

      Attachments

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

        Activity

          People

            inho Inho Lee
            skoh-qt Sze Howe Koh
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes