实现代码:
import QtQuick 2.0
import QtQuick.Controls 2.4
import "qrc:/source/components"
Dialog {
header: null
footer: null
width: window.width
height: window.height
background: Rectangle {
color: Qt.rgba(1,1,1,0)
}
modal: false
closePolicy: Popup.NoAutoClose
z: 1000
QtObject{
id: attrs;
property int counter;
Component.onCompleted: {
attrs.counter = 20;
}
}
//定时器,超过20s后强制关闭,避免无法进行其他交互
Timer{
id:countDown
interval: 1000
repeat: true
triggeredOnStart: true
onTriggered: {
attrs.counter -= 1
if(attrs.counter < 0 )
{
close()
animatedImage.paused = true
countDown.stop()
}
}
}
AnimatedImage {
id: animatedImage
anchors.centerIn: parent
width: 90
height: 90
paused: true
source: '/assets/images/loading.gif'
}
function show() {
open()
attrs.counter = 20;
animatedImage.currentFrame = 1
animatedImage.paused = false
countDown.start();
}
function hide() {
close()
animatedImage.paused = true
countDown.stop()
}
}
在main.qml 中声明,全局可使用
HudProgress {
id: loading
}
使用方法:
loading.show()
loading.hide()