QML Image Element
QML Image Element
The Image element displays an image in a declarative user interface More...
Image元素在一个声明式的用户接口中显示一张图片。
Inherits Item
Inherited by AnimatedImage.
Properties
- asynchronous : bool
- fillMode : enumeration
- paintedHeight : real
- paintedWidth : real
- progress : real
- smooth : bool
- source : url
- sourceSize : QSize
- status : enumeration
Detailed Description
The Image element is used to display images in a declarative user interface.
Image元素用来显示图片。
The source of the image is specified as a URL using the source property. Images can be supplied in any of the standard image formats supported by Qt, including bitmap formats such as PNG and JPEG, and vector graphics formats such as SVG. If you need to display animated images, use the AnimatedImageelement.
图片通过source属性来指定来源。Image支持各种标准格式的图片,包括bitmap,png,jpeg,svg。如果想显示图片动画,请使用AnimatedImage元素。
If the width and height properties are not specified, the Image element automatically uses the size of the loaded image. By default, specifying the width and height of the element causes the image to be scaled to that size. This behavior can be changed by setting the fillMode property, allowing the image to be stretched and tiled instead.
如果width和height属性没有指定,则使用图片真实的width和height。通常是通过指定width和height来实现图片缩放,这里可以通过设置fillMode属性来设置是否允许图片拉伸或是平铺。
Example Usage
The following example shows the simplest usage of the Image element.
下面一个例子显示了一个Image元素的最简单用法。
- import QtQuick 1.0
- Image {
- source: "pics/qtlogo.png"
- }
- <span style="font-size:18px;"> import QtQuick 1.0
- Image {
- source: "pics/qtlogo.png"
- }
- </span>
Performance
By default, locally available images are loaded immediately, and the user interface is blocked until loading is complete. If a large image is to be loaded, it may be preferable to load the image in a low priority thread, by enabling the asynchronous property.
默认情况下,程序启动前会马上加载本地图片,而用户接口则等到图片加载完了之后才开始显示。如果加载的图片比较大则等待时间会比较长,这时可以将asynchronous属性置为真。
If the image is obtained from a network rather than a local resource, it is automatically loaded asynchronously, and the progress and status properties are updated as appropriate.
如果图片是来自网络下载,则asynchronous属性自动为真,而progress属性和status属性也会随着下载的进度自动更新。
Images are cached and shared internally, so if several Image elements have the same source, only one copy of the image will be loaded.
图片会被缓存并做内部共享,同一个图片只会被加载一次并且只有一个拷贝。
Note: Images are often the greatest user of memory in QML user interfaces. It is recommended that images which do not form part of the user interface have their size bounded via the sourceSize property.
This is especially important for content that is loaded from external sources or provided by the user.
注意:图片往往是QML中消耗内存最多,建议将用户界面不需要的图片的size自动绑定到其sourceSize,特别是作为外部资源图片或是用户提供的图片。
See also Image example and QDeclarativeImageProvider.
Property Documentation
asynchronous : bool |
Specifies that images on the local file system should be loaded asynchronously in a separate thread. The default value is false, causing the user interface thread to block while the image is loaded. Setting asynchronous to
true is useful where maintaining a responsive user interface is more desirable than having images immediately visible.
默认值为假,此时用户接口线程会阻塞知道将图片加载完。如果asynchronous为真则会在另外一个线程中加载图片,不会阻塞用户接口线程。
Note that this property is only valid for images read from the local filesystem. Images loaded via a network resource (e.g. HTTP) are always loaded asynchonously.
注意这个属性只对读取本地的图片有效,网络资源图片则总是在另外一个线程中加载。
fillMode : enumeration |
Set this property to define what happens when the image set for the item is smaller than the size of the item.
fillMode属性用来定义当图片大小设置小于item大小时的填充方式。
- Image.Stretch - the image is scaled to fit
- 此时图片会被拉伸到item的大小。Image.Stretch是fillMode的默认填充方式。
- Image.PreserveAspectFit - the image is scaled uniformly to fit without cropping
- 此时图片会统一缩放,没有剪切。
- Image.PreserveAspectCrop - the image is scaled uniformly to fill, cropping if necessary
- 此时图片会被统一缩放,如果有必要则会剪切。
- Image.Tile - the image is duplicated horizontally and vertically
- 在垂直和水平方向平铺图片。
- Image.TileVertically - the image is stretched horizontally and tiled vertically
- 图片水平方向拉伸,垂直方向平铺
- Image.TileHorizontally - the image is stretched vertically and tiled horizontally
- 图片水平方向平铺,垂直方向拉伸。
Stretch (default)
|
|
PreserveAspectFit
Image { |
|
PreserveAspectCrop
|
|
Tile
Image { |
|
TileVertically
|
|
TileHorizontally
Image { |
See also Image example.
These properties hold the size of the image that is actually painted. In most cases it is the same as width and height, but when using a fillMode PreserveAspectFit or fillMode PreserveAspectCrop paintedWidth or paintedHeight can be smaller or larger than width and height of the Image element.
read-onlyprogress : real |
This property holds the progress of image loading, from 0.0 (nothing loaded) to 1.0 (finished).
progress属性表明图片加载进度,0.0表示没有加载,1.0表示加载完成。
See also status.
smooth : bool |
Set this property if you want the image to be smoothly filtered when scaled or transformed. Smooth filtering gives better visual quality, but is slower. If the image is displayed at its natural size, this property has no visual or performance effect.
如果设置smooth属性为真则当图片缩放或是向量变换会给予图片比较好的显示效果,但这将导致速度变慢。如果图片显示是其固有大小则没有影响。
Note: Generally scaling artifacts are only visible if the image is stationary on the screen. A common pattern when animating an image is to disable smooth filtering at the beginning of the animation and reenable
it at the conclusion.
source : url |
Image can handle any image format supported by Qt, loaded from any URL scheme supported by Qt.
The URL may be absolute, or relative to the URL of the component.
See also QDeclarativeImageProvider.
sourceSize : QSize |
This property holds the actual width and height of the loaded image.
sourceSize属性指明了加载图片的实际宽度和高度。
Unlike the width and height properties, which scale the painting of the image, this property sets the actual number of pixels stored for the loaded image so that large images do not use more memory than necessary. For example, this ensures the image in memory is no larger than 1024x1024 pixels, regardless of the Image's width and height values:
width/height属性用来缩放图像,而QSize实际上指出了内存中加载这个图片在水平方向和垂直方向上的像素数,即这个图片的分辨率。在下面这个例子中,限制了图片的分辨率为1024X1024,而不管图片的width属性和height属性。
- Rectangle {
- width: ...
- height: ...
- Image {
- anchors.fill: parent
- source: "reallyBigImage.jpg"
- sourceSize.width: 1024
- sourceSize.height: 1024
- }
- }
- <span style="font-size:18px;"> Rectangle {
- width: ...
- height: ...
- Image {
- anchors.fill: parent
- source: "reallyBigImage.jpg"
- sourceSize.width: 1024
- sourceSize.height: 1024
- }
- }
- </span>
image's aspect ratio. (The fillMode is
independent of this.)
to an image.
If the source is a non-scalable image (eg. JPEG), the loaded image will be no greater than this property specifies. For some formats (currently only JPEG), the whole image will never actually be loaded into memory.
对于不可缩放的图片(例如JPEG),加载的图片将不会比这个属性大。实际上对于JPEG图片来说,整个图片并没有真正全部加载到内存中。
Note: Changing this property dynamically causes the image source to be reloaded, potentially even from the network, if it is not in the disk cache.
注意这个属性不能动态改变,否则图片奖重新加载,如果这个图片来自网络则重新下载。
read-onlystatus : enumeration |
This property holds the status of image loading. It can be one of:
status属性表明图片加载的状态。可取如下值:
- Image.Null - no image has been set
- Image.Null 表明没有设置图片
- Image.Ready - the image has been loaded
- Image.Ready 表明图片已经加载完毕
- Image.Loading - the image is currently being loaded
- Image.Loading 表明图片正在加载
- Image.Error - an error occurred while loading the image
- Image.Error 表明加载图片时出错
Use this status to provide an update or respond to the status change in some way. For example, you could:
我们可以使用status来做一些针对图片加载完毕后的一些处理。如下例所示:
- Trigger a state change:
State { name: 'loaded'; when: image.status == Image.Ready }
- Implement an onStatusChanged signal handler:
- Image {
- id: image
- onStatusChanged: if (image.status == Image.Ready) console.log('Loaded')
- }
- <span style="font-size:18px;"> Image {
- id: image
- onStatusChanged: if (image.status == Image.Ready) console.log('Loaded')
- }
- </span>
- Bind to the status value:
Text { text: image.status == Image.Ready ? 'Loaded' : 'Not loaded' }
- 顶
- 0
- 踩
QML Image Element的更多相关文章
- QML Flipable、Flickable和状态与动画 上篇
本文介绍的是QML Flipable.Flickable和状态与动画,我们以前接触过QML组件,和一些QML相关的内容,那么本文介绍的内容就很明了了.先来看内容. AD:51CTO 网+ 第十二期沙龙 ...
- QML学习【一】Basic Types
QML入门教程(1) QML是什么? QML是一种描述性的脚本语言,文件格式以.qml结尾.语法格式非常像CSS(参考后文具体例子),但又支持javacript形式的编程控制.它结合了QtDesi ...
- qml操作播放器
现在增加了一个filter属性,所以可以很好和opencv结合.转一篇文章(http://blog.qt.io/blog/2015/03/20/introducing-video-filters-in ...
- qt 学习之路 :QML 语法
前面我们已经见识过 QML 文档.一个 QML 文档分为 import 和对象声明两部分.如果你要使用 Qt Quick,就需要 import QtQuick 2.QML 是一种声明语言,用于描述程序 ...
- QML 语言基础
在<Qt Quick 简单介绍>中我们提到 QML 语法和 Json 相似,请參考<Qt on Android: http下载与Json解析>查看 Json 语法.当然这里我们 ...
- Qt(QML)本地化
Internationalization and Localization with Qt Quick 程序国际化 1) Use qsTr() for all Literial UI strings ...
- OpenLayers学习笔记(三)— QML与HTML通信之 地图上点击添加自由文本
实现在地图随意点击,弹出文本输入框,输入任意文字,完成自由文本添加的功能 作者: 狐狸家的鱼 GitHub:八至 本文链接:地图上点击添加自由文本 关于如何QML与HTML通信已经在上一篇文章 QML ...
- QML 从入门到放弃
发现了一个问题: QQuickView only supports loading of root objects that derive from QQuickItem. If your examp ...
- QT qml TreeView展示数据结构于界面
Class QAbstractItemModel: 使用QML的TreeView类来展示树状的结构,对应的是QT的Model/View模型.这个model是一个数据模型,要为TreeView提供一个 ...
随机推荐
- IOS实现打电话后回调
本文转载至 http://blog.csdn.net/cerastes/article/details/38340687 UIWebView *callWebview =[[UIWebView a ...
- python虚拟机运行原理
近期为了面试想要了解下python的运行原理方面的东西,奈何关于python没有找到一本类似于深入理解Java虚拟机方面的书籍,找到了一本<python源码剖析>电子书,但是觉得相对来说最 ...
- 【BZOJ1898】[Zjoi2005]Swamp 沼泽鳄鱼 矩阵乘法
[BZOJ1898][Zjoi2005]Swamp 沼泽鳄鱼 Description 潘塔纳尔沼泽地号称世界上最大的一块湿地,它地位于巴西中部马托格罗索州的南部地区.每当雨季来临,这里碧波荡漾.生机盎 ...
- 深度解析Objective-C笔试题
2011-08-11 17:39 佚名 互联网 字号:T | T 本文介绍的是Objective-C笔试题,先来问一个,为什么很多内置类如UITableViewController的delegate属 ...
- coderfun-boot接私活利器,文档详实,非一般的开发速度
项目主页:https://gitee.com/klguang/coderfun-boot 演示地址:http://106.15.195.9:8080/admin/项目文档:https://www.ka ...
- 巨蟒python全栈开发flask10 项目开始2
1.websocket异常处理 出现上图报错的原因是什么? 原因是:websocket断开了,所以报错 19行接收的msg是None值,所以报错. 打开一个文件,点击发送音乐,出现上面的内容: 客户端 ...
- window.location下的属性说明
属性 说明 window.location.href 完整的url window.location.protocol 协议 window.location.hostname 主机名 window.lo ...
- 转:Java并发编程与技术内幕:线程池深入理解
版权声明:本文为博主林炳文Evankaka原创文章,转载请注明出处http://blog.csdn.net/evankaka 目录(?)[+] ); } catch (InterruptedExcep ...
- linux页缓存
2017-04-25 本节就聊聊页缓存这个东西…… 一.概述 页缓存是一个相对独立的概念,其根本目的是为了加速对后端设备的IO效率,比如文件的读写.页缓存顾名思义是以页为单位的,目前我能想到的在两个地 ...
- windows通过ssh连接虚拟机中的ubuntu步骤
linux端开启ssh服务 1.安装openssh-server包 sudo apt-get install openssh-server 2.启动ssh server sudo /etc/init. ...