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提供一个 ...
随机推荐
- nginx 服务器重启命令,关闭(转)
nginx -s reload :修改配置后重新加载生效 nginx -s reopen :重新打开日志文件nginx -t -c /path/to/nginx.conf 测试nginx配置文件是 ...
- AVR 定时器快速PWM模式使用
PWM很常用,AVR自带内部PWM功能,分为快速PWM模式和相位修正PWM模式. 我们这里选择方式15 ,由OCR1A保存上限值,由OCR1B保存匹配值,所以输出管脚 OCR1A不能输PWM,只能 ...
- IOS7开发~新UI学起(三)
1.UITextView: A ) IOS7新增加的 UITextViewDelegate 方法: - (BOOL)textView:(UITextView *)textView shoul ...
- highcharts配置的效果如下
配置如下: function init(categoryArray,seriesData,month_first_day,month_last_day,currDay){ var chart = Hi ...
- linux如何查看端口是否被占用?
转自:https://www.cnblogs.com/hindy/p/7249234.html LINUX中如何查看某个端口是否被占用 之前查询端口是否被占用一直搞不明白,问了好多人,终于搞懂了,现在 ...
- HighCharts使用心得(转载)
转载自:http://www.cnblogs.com/Olive116/p/3777021.html 1. 准备工作------下载HighCharts插件 跟ECharts一样,HighChart ...
- [Shell] 简单的自动检查ssh代理是否正常的脚本
As Follows: #!/bin/bash RESPONSE=`curl -s --socks5 www.123cha.com` -eq $? ] then echo SUCCESS else e ...
- Spark Streaming Programming Guide
参考,http://spark.incubator.apache.org/docs/latest/streaming-programming-guide.html Overview SparkStre ...
- 搭建SpringbootAdmin监控中心报错A attempt was made to call the method reactor.retry.Retry.retryMax(I)Lreactor/ret)
遇到了同样的错误,转载记录下: 转载自:https://blog.csdn.net/qq_41938882/article/details/85048953 很明显,还没有启动成功就报错了.报错原 ...
- 前端开发 - CSS - 下
CSS: 12.display 13.浮动效果 14.浮动特性 15.浮动产生的问题和解决方法 16.float京东导航栏 17.position 18.z-index 19.京东案例 12.disp ...





