我想展示一段BusyIndicator
漫长的过程。问题是当我让它运行时它不显示,然后在过程完成时显示。根据文档
忙碌指示符应该用于指示正在加载内容或 UI 被阻止等待资源可用时的活动。
我创建了一个基于原始代码的最小代码
Window {
id: win
width: 300
height: 300
property bool run : false
Rectangle {
anchors.fill: parent
BusyIndicator {
anchors.centerIn: parent
running: run
}
MouseArea {
anchors.fill: parent
onClicked: {
run = true
for(var a=0;a<1000000;a++) { console.log(a) }
run = false
}
}
}
}
因此,当Rectangle
单击 时,我想显示BusyIndicator
计算完成之前的时间。
例如,我在这里使用了 for 循环。在实际场景中,我通过ContextProperty
. 但在这种情况下,BusyIndicator
也不会显示。
我做对了吗?或者最好的方法是什么?