qml的图元控件是Image, 基本使用如下:
import QtQuick 2.12
import QtQuick.Window 2.12
import QtQuick.Controls 2.5
Window {
visible: true
width: 640
height: 480
title: qsTr("Hello World")
Image{
id:img
width:400
height: 400
anchors.centerIn: parent
source: "/pic/1.png"
}
}
显示效果
Image显示图片,只要是Qt支持的,比如JPG、PNG、BMP、GIF、sVG等都可以显示。它只能显示静态图片,对于GIF等格式,只会把第一帧显示出来。如果要显示动画,则可以使用 AnimatedSprite 或者 AnimatedImage。 Image 的 width 和 height 属性用来设定图元的大小,如果没有设置它们,则使用图片本身的尺寸,如果设置了width 和 height,图片显示时会进行相应的拉伸。
除了显示本地图片还可以显示网络图片,设置source属性为网络地址即可,http, ftp等。
Image加载图片时,默认是阻塞的形式,如果图片比较大可以