Details
-
Bug
-
Resolution: Unresolved
-
P2: Important
-
None
-
5.15.12, 6.2.7, 6.4.2, 6.5.0 Beta1
-
Windows 10 Pro 22H2 + MSVC 2019 x64; Ubuntu 22.04 (Xorg) + GCC 11.3.0
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)