前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Qml控件之Spin加载中

Qml控件之Spin加载中

作者头像
Qt君
发布2023-03-17 14:51:40
6050
发布2023-03-17 14:51:40
举报
文章被收录于专栏:跟Qt君学编程跟Qt君学编程

❝Spin(加载中)控件是基于Qml实现的,它兼容于QtQuick 1.xQtQuick 2.x。可用于页面和区块的加载中状态。❞

1. 演示

2. 例子

代码语言:javascript
复制
import QtQuick 2.0 // Qt4 版本改为:import QtQuick 1.0

Rectangle {
    id: root
    width: 320
    height: 240

    Grid {
        anchors.centerIn: parent
        rows: 2
        columns: 2
        spacing: 80

        Spin { } // defualt
        Spin { color: "#a9cf6c" }
        Spin { color: "#fde498" }
        Spin { color: "#4169E1" }
    }
}

3. 使用场景

  页面等待异步数据或正在渲染过程时,合适的加载动画会有效缓解用户的焦虑,从而提升用户体验。

4. 实现

  四个Rectangle构造圆形并使用了动画类(NumberAnimation)。

5. 源码获取

  • 「可在公众号聊天界面回复"入群"后在群文件获取源码。」
代码语言:javascript
复制
/*
 * Author: Qt君
 * WebSite: qthub.com
 * Email: 2088201923@qq.com
 * QQ交流群: 732271126
 * 关注微信公众号: [Qt君] 第一时间获取最新推送.
 * 代码仅用于学习使用,请勿用于商业途径.
 */
import QtQuick 2.0 // Qt4 版本改为:import QtQuick 1.0

FocusScope {
    id: root
    property color color: "#2f9bff"
    width: 40
    height: width

    Grid {
        id: grid
        anchors.centerIn: parent
        rows: 2
        columns: 2
        spacing: root.width * 0.2
        
        Repeater {
            model: [
                Qt.darker(color, 1.0),
                Qt.darker(color, 0.95),
                Qt.darker(color, 0.90),
                Qt.darker(color, 0.85),
                ]
            Rectangle {
                width: root.width * 0.3
                height: width
                color: modelData
                radius: width/2
            }
        }
    }
    
    Item {
        anchors.top: parent.bottom
        anchors.topMargin: 10
        width: root.width
        height: root.height * 0.3
        Text {
            anchors.centerIn: parent
            text: "loading..."
            font.pixelSize: 15
        }   
    }

    NumberAnimation {
        target: grid
        running: true
        property: "rotation"
        loops: Animation.Infinite
        from: 0
        to: 360
        duration: 1000
    }
}
本文参与 腾讯云自媒体分享计划,分享自微信公众号。
原始发表:2021-01-01,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 Qt君 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 1. 演示
  • 2. 例子
  • 3. 使用场景
  • 4. 实现
  • 5. 源码获取
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档