qt - QML RotationAnimation 不旋转
问题描述
我正在尝试将矩形从指定角度旋转到指定角度,但我不确定我是否理解文档。我下面的代码运行,我开始和完成的插槽打印正确的角度。但是矩形没有在屏幕上旋转。我错过了什么?
Rectangle {
width: 100
height: 100
RotationAnimation {
id: rotateCritter
duration: 1000
property real lastAngle: 0
onStarted: {
lastAngle = to;
console.log("Rotating from "+from+" to "+to)
}
onStopped: {
console.log("Done rotating from "+from+" to "+to)
from = lastAngle;
}
}
}
// On click totate the critter to the new angle
rotateCritter.to = 45
rotateCritter.start()
解决方案
您RotationAnimation
缺少一个target
. 虽然它是 的孩子,但Rectangle
这种关系不会自动Rectangle
生成target
动画的 ;它必须是明确的。我已经给出了Rectangle
一个id
and color
,并把它变成target
了动画的:
Rectangle {
id: critter
width: 100
height: 100
color: "red"
RotationAnimation {
id: rotateCritter
target: critter
duration: 1000
property real lastAngle: 0
onStarted: {
lastAngle = to;
console.log("Rotating from "+from+" to "+to)
}
onStopped: {
console.log("Done rotating from "+from+" to "+to)
from = lastAngle;
}
}
}
推荐阅读
- javascript - Ammo js旋转运动学对象
- reactjs - 在 reducer 函数中更改操作对象的类型
- javascript - 使用时刻 js 格式化 OffsetDataTime 时不显示本地时区
- c++ - 是否是取消引用指针的UB?
- android - 需要在使用 MLKit 和 Camera2 进行人脸检测期间捕获静止图像
- elasticsearch - 使用 Term/Range 查询时查找 0 值的问题
- wcf - 无法从客户端成功发布到 WCF WSDL 服务
- cocoa - NSBox/NSTitleCell 可以不是 NSTextFieldCell 吗?
- c++ - C++ 概念复合要求和返回类型要求
- python - 在python任务计划中使用无限while循环时无法启动项目服务器