Qml自定义等待指示器

QtQuick.Controls 2 大部分组件提供的定制化一般都是 contentItem和background

contentItem描述组件的可视化区域的显示效果
background描述组件的背景区域的显示效果

自定义BusyIndicator可视化区域的显示

/*!
 *@file QmlBusyIndicator.qml
 *@brief Qml自定义等待指示器
 *@version 1.0
 *@section LICENSE Copyright (C) 2003-2103 CamelSoft Corporation
 *@author zhengtianzuo
*/
import QtQuick 2.7
import QtGraphicalEffects 1.0

Item {

    Rectangle {
        id: rect
        width: parent.width
        height: parent.height
        color: Qt.rgba(0, 0, 0, 0)
        radius: width / 2
        border.width: width / 6
        visible: false
    }

    ConicalGradient {
        width: rect.width
        height: rect.height
        gradient: Gradient {
            GradientStop { position: 0.0; color: "#80c342" }
            GradientStop { position: 1.0; color: "#006325" }
        }
        source: rect

        Rectangle {
            anchors.top: parent.top
            anchors.horizontalCenter: parent.horizontalCenter
            width: rect.border.width
            height: width
            radius: width / 2
            color: "#006325"
        }

        RotationAnimation on rotation {
            from: 0
            to: 360
            duration: 800
            loops: Animation.Infinite
        }
    }
}

使用:

    BusyIndicator {
        id: busyIndicator
        anchors.centerIn: parent
        implicitWidth: 96
        implicitHeight: 96
        opacity: running ? 0.0 : 1.0
        contentItem: QmlBusyIndicator{}
    }

主要最后一句, 设置contentItem为我们上面的自定义等待指示器

show.gif

需要完整代码请访问QtQuickExamples

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 1、通过CocoaPods安装项目名称项目信息 AFNetworking网络请求组件 FMDB本地数据库组件 SD...
    阳明AI阅读 16,020评论 3 119
  • <<叶武滨时间管理100讲>> 2018/09/18 输入打卡: 02【早起】美好的一天从如何起床开始 大家好!我...
    小丽1212阅读 389评论 0 1
  • 2018-06-10 随笔日记6 今天去吃火锅自助,感触颇深。平常和朋友聚餐多是去自助餐厅,各种素食,海鲜,烧烤,...
    芝麻糖_f0e2阅读 148评论 0 0
  • MISC-welcome 记事本打开发现文件头BM,改后缀bmp 扔stegsolve,analyse->ster...
    ylylhl阅读 648评论 0 1
  • 我们曾说5月是赚钱的。5月过了,我们重点在次新股里,好像还可以。 6月呢?6月能活着,都是一个奇迹! ...
    陈伟sky_ccs阅读 561评论 0 1