【QT学习】qml中实现文字的逐个显示

38 篇文章 0 订阅

 效果:文字能逐个显示,然后全部消失,然后再逐个显示。

import QtQuick 2.9
import QtGraphicalEffects 1.0


Rectangle{
    property var textVar: ["等","待","确","认"," ."," ."," ."]
    property var textIndex: 0

    color: "transparent"
    width: 250
    height: 50


    Item
    {
        id:waitItem
        anchors.left: parent.left
        anchors.leftMargin: 15
        anchors.verticalCenter: parent.verticalCenter
        implicitHeight: 30
        implicitWidth: 30
        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: "#87CEFF" }
                GradientStop
                {
                    position: 1.0;
                    color: "blue"
                }
            }
            source: rect
            Rectangle {
                anchors.top: parent.top
                anchors.horizontalCenter: parent.horizontalCenter
                width: rect.border.width
                height: width
                radius: width / 2
                color: "blue"
            }
            RotationAnimation on rotation {
                from: 0
                to: 360
                duration: 800
                loops: Animation.Infinite
            }
        }
    }

    Text
    {
        id:scrollText
        height:parent.height
        anchors.left: waitItem.right
        anchors.leftMargin: 15

        color:"white"
        //font.bold: true
        font.pixelSize: 22
        verticalAlignment: Text.AlignVCenter
        text: ""

    }
    Timer
    {
        id:textTimer
        interval: 1000
        running: true
        repeat: true
        onTriggered:
        {
            if(textIndex == textVar.length)
            {
                scrollText.text = ""
                textIndex = 0;
                return;
            }
            scrollText.text = scrollText.text + textVar[textIndex]
            textIndex++;
        }

    }

}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值