我想展示一个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
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
因此,当Rectangle单击时,我想显示BusyIndicator时间直到计算完成.
例如,我在这里使用了for循环.在实际场景中,我通过调用一个函数(在数据库中插入大约1000行)ContextProperty.但在那种情况下,BusyIndicator也没有显示.
我是以正确的方式做到的吗?或者最好的方法是什么?