qml实现网络请求loading

实现代码:

import QtQuick 2.0
import QtQuick.Controls 2.4

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

    AnimatedImage {
        id: animatedImage
        anchors.centerIn: parent
        width: 90
        height: 90
        paused: true
        source: '/assets/images/loading.gif'
    }

    function show() {
        open()
        animatedImage.currentFrame = 1
        animatedImage.paused = false
    }

    function hide() {
        close()
        animatedImage.paused = true
    }
}

在main.qml 中声明,全局可使用

HudProgress {
	id: loading
}

使用方法:

loading.show()
loading.hide()

你可能感兴趣的:(qml)