这段 QML 代码有问题吗?需要怎么修改呢?
Timer {
id: timer2
interval:1000 // 每隔 1 秒触发一次
running: true // 启动定时器
repeat: true // 重复触发
onTriggered: {
var animation = PropertyAnimation {
target: rect
property: ["x", "y"]
to: Qt.point(Math.random() * (parent.width - rect.width), Math.random() * (parent.height - rect.height))
duration:1000 // 动画持续时间为 1 秒
easing.type: Easing.InOutQuad // 缓动函数为 InOutQuad
}
animation.start() // 启动属性动画
}
}
注意看96行少了一个;
,加上试一下?
onTriggered: {
var animation = PropertyAnimation {
target: rect
property: ["x", "y"]
to: Qt.point(Math.random() * (parent.width - rect.width), Math.random() * (parent.height - rect.height))
duration:1000 // 动画持续时间为 1 秒
easing.type: Easing.InOutQuad // 缓动函数为 InOutQuad
}; //这个位置加一个逗号试一下
animation.start() // 启动属性动画
}
这段QML代码没有问题,可以直接使用。它创建了一个宽高均为100的红色矩形,四个角都有10像素的圆角。没有必要进行修改。