qml显示gif动画

在Qt中可以用QMive加QLable显示Gif动,而在Qml中,有一个专门的控件显示Gif,即AnimatedImage

AnimatedImage 提供了五个属性:

    currentFrame,指示当前正在播放的帧序号
    frameCount,指示图片的总帧数
    paused,表示是否暂停,设置它也可以暂停或继续播放
    playing,指示动画是否在播放,默认为 true ,意思是 AnimatedImage 对象创建后立即开始播放
    source,类型为 url ,指定要播放的图片地址,可以使本地文件、 qrc 里的资源、网络文件

使用代码示例如下

import QtQuick 2.12
import QtQuick.Window 2.12
import QtQuick.Controls 2.12

Window {
    visible: true
    width: 640
    height: 480
    title: qsTr("Hello World")
    //color: "blue"

    AnimatedImage {
        id: animated
        source: "qrc:/aa.gif"

        onCurrentFrameChanged: {
            info.text = ("%1/%2").arg(animated.currentFrame).arg(animated.frameCount)
        }
    }

    Row {
        spacing: 4
        anchors.horizontalCenter: parent.horizontalCenter
        anchors.bottom: parent.bottom
        anchors.bottomMargin: 10

        Text {
            id: info
            text: qsTr("text")
            width: 80; height: 24;
            color: "blue"
            font.pixelSize: 20
            verticalAlignment: Text.AlignVCenter
            horizontalAlignment: Text.AlignRight
        }

        Button {
            width: 60;
            height: 24
            text: (animated.paused == true) ? "Play" : "Pause";
            onClicked: {
                animated.paused = !animated.paused;
            }
        }
    }
}


运行效果:

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值