AnimatedImage
ImportStatement:
Inherits:
Properties
currentFrame : int
frameCount : int
paused : bool
playing : bool
source : url
DetailedDescription
AnimatedImage元件扩展了图片的特征类型。它提供了播放动画图片的方式。这些动画图片存储在图片上,如GIF文件。当前帧的信息和动画的长度,可以访问currentFrame和frameCount属性获得。我们能通过访问playing和paused属性来暂停或停止动画。这个元件支持的完整格式列表,在QMovie::supportedFormats()中定义。
下面的QML展示了如何显示动画图片,并从中获得当前帧和帧总数的信息,在动画的下方显示为一个简单的进度条。
注意:不像图片,动画图片不会缓存和共享。
import QtQuick 2.0
Rectangle {
width: animation.width; height: animation.height +8
AnimatedImage { id: animation; source:"animation.gif" }
Rectangle {
property int frames: animation.frameCount
width: 4; height: 8
x: (animation.width - width) *animation.currentFrame / frames
y: animation.height
color: "red"
}
}
同时看BorderImage和Image。
PropertyDocumentation
currentFrame : int
当前帧是当前正在显示的帧,通过监控这个帧,我们可以在某帧显示的同时,做些其他事情。
frameCount : int
帧数是当前动画的帧总数。对一些动画来说,帧数是未知的,其值为0。
paused : bool
动画是否暂停。默认为假。当我们想暂停动画时,,设置它为真。
playing : bool
当前动画是否在播放。默认为真。AnimatedImage的实际播放状态会影响这个属性的值。如果使用非动画的图像,需要手动设置这个属性为真,以驱动动画。
AnimatedImage {
onStatusChanged: playing = (status ==AnimatedImage.Ready)
}
source : url
动画的资源位置。AnimatedImage能支持Qt支持的图片格式。
同时参阅QQuickImageProvider。