以图形方式显示剩余时间
Graphically showing remaining time
让我们假设用户有 t
毫秒进行点击,0 < t < 5000
。我们想以图形方式显示剩余时间。假设用户必须在 t
.
内再次单击按钮
property int startTime
property int fps: 40
property int t: 1000 // for example
Button
{
id: btn
text: "Click me!"
onClicked:
{
text = "Click again!"
startTime = new Date().getTime()
timer.restart()
}
}
Timer
{
id: timer
interval: 1000 / fps
onTriggered:
{
var progress = (new Date().getTime() - startTime) / t
if (progress < 1)
{
pb.value = progress
restart()
}
else
{
pb.value = 1
btn.text = "Try again"
}
}
}
ProgressBar
{
id: pb
value: 0
}
我只担心性能影响。 UI 应始终保持可访问性并对点击做出快速反应,因为 t
可能很低。如果不是,用户可以在设置的时间内单击按钮,但 "lose",因为应用程序不会响应单击。
我应该担心性能下降吗?有没有办法避免它?我希望我的应用程序在低端设备上也是 运行。
我在 Android
上使用 Qt
如果 fps
合理,那么我认为性能不会成为问题并且 UI 将保持响应。
反正我觉得优雅用动画达到同样的效果...你可以用一个NumberAnimation
来不断更新的值进度条,然后在你想开始计算剩余时间的时候开始动画...
让我们假设用户有 t
毫秒进行点击,0 < t < 5000
。我们想以图形方式显示剩余时间。假设用户必须在 t
.
property int startTime
property int fps: 40
property int t: 1000 // for example
Button
{
id: btn
text: "Click me!"
onClicked:
{
text = "Click again!"
startTime = new Date().getTime()
timer.restart()
}
}
Timer
{
id: timer
interval: 1000 / fps
onTriggered:
{
var progress = (new Date().getTime() - startTime) / t
if (progress < 1)
{
pb.value = progress
restart()
}
else
{
pb.value = 1
btn.text = "Try again"
}
}
}
ProgressBar
{
id: pb
value: 0
}
我只担心性能影响。 UI 应始终保持可访问性并对点击做出快速反应,因为 t
可能很低。如果不是,用户可以在设置的时间内单击按钮,但 "lose",因为应用程序不会响应单击。
我应该担心性能下降吗?有没有办法避免它?我希望我的应用程序在低端设备上也是 运行。 我在 Android
上使用 Qt如果 fps
合理,那么我认为性能不会成为问题并且 UI 将保持响应。
反正我觉得优雅用动画达到同样的效果...你可以用一个NumberAnimation
来不断更新的值进度条,然后在你想开始计算剩余时间的时候开始动画...