我正在尝试在QML中创建一个平滑变化的列表,但动画会产生意想不到的副作用。这是我的玩具代码,每次调整窗口大小时都会移动项目:
import QtQuick 2.5
import QtQuick.Window 2.2
Window {
visible: true
ListView {
id: listView1
x: 0
y: 0
width: parent.width
height: parent.height
onWidthChanged: {
model.move(0,1,2);
}
move: Transition {
SmoothedAnimation {
properties: "x,y"
duration: 1000
}
}
displaced: Transition {
SmoothedAnimation {
properties: "x,y"
duration: 1000
}
}
delegate: Item {
x: 5
onXChanged: {
console.log("x: ", x)
}
width: parent.width
height: 40
Text {
text: name
anchors.verticalCenter: parent.verticalCenter
font.bold: true
}
}
model: ListModel {
ListElement {
name: "Grey"
}
ListElement {
name: "Red"
}
ListElement {
name: "Blue"
}
}
}
}
奇怪的是,这是我玩那个窗口时的输出:
QML debugging is enabled. Only use this in a safe environment.
qml: x: 0.7840000000000007
qml: x: 0
qml: x: 1.2960000000000003
qml: x: 0
qml: x: 1.2960000000000003
qml: x: 0
这不仅仅是暂时的,有些物品永久性地改变了它们的x位置。这是我的错吗?