【问题标题】:Showing a busy indicator or a loading image while loading large QML file加载大型 QML 文件时显示繁忙指示器或加载图像
【发布时间】:2020-09-03 12:31:04
【问题描述】:

我正在开发基于 QML 的应用程序。我在其中动态加载内容。但是,在运行应用程序时需要很长时间(5-10 秒),所以我需要在加载整个内容时显示任何加载屏幕或指示器。谁能建议我怎么做? 例如,在我登录我的应用程序后,需要一些时间来加载下一页,所以在这段时间内我想显示加载屏幕。

App {
id: app
height: 400
width: 200
    Rectangle {
        id: rectangle       
        Button {
            id: button
            text: qsTr("GO TO NEXT PAGE")
            onClicked:stackView.push("page2.qml")                
        }        
        Image {
            id: image
            fillMode: Image.PreserveAspectFit
            source: "default-app.png"
        }
    }

} 假设这是我的代码,那么我在哪里可以使用 loader?以前没用过

【问题讨论】:

  • 对不起,这里提到的StackView在哪里?

标签: qt qml


【解决方案1】:

您可以使用Loader 组件中的status(我猜您正在使用它,因为您正在“动态”加载)。然后在 BusyIndicator 中使用它。

Loader {
    id: loader
    asynchronous: true
    ...

    BusyIndicator {
         anchors.centerIn: parent
         running: loader.status == Loader.Loading 
    }
}

哎呀,Qt docs for BusyIndicator 应该让你继续前进!

【讨论】:

  • Ohne 也应该设置asynchronous: true
  • 我没用过loader。重定向到下一页我使用stackView
  • @user13846567 表明您应该在问题中包含代码!然后你应该开始在你的StackView中使用Loader
猜你喜欢
  • 1970-01-01
  • 2012-05-28
  • 2012-04-10
  • 2020-06-11
  • 1970-01-01
  • 2010-12-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多