C

Image QML Type

Displays an image. More...

Import Statement: import QtQuick .
Since: Qt Quick Ultralite 1.0
Inherits:

Item

Inherited By:

ColorizedImage

Properties

Detailed Description

The Image type displays an image.

The source of the image is specified as a resource URI using the source property. Images resources are made available through the qulrcc resource compiler. By default, images are decompressed before being embedded into the binary and thus any of the standard image formats supported by Qt, including bitmap formats such as PNG and JPEG, and vector graphics formats such as SVG are supported. The following table lists all the supported formats:

FormatDescription
BMPWindows Bitmap
DDSDirect Draw Surface
GIFGraphic Interchange Format (optional)
ICNSApple Icon Image
JP2Joint Photographic Experts Group 2000
JPGJoint Photographic Experts Group
JPEGJoint Photographic Experts Group
MNGMultiple-image Network Graphics
PNGPortable Network Graphics
PBMPortable Bitmap
PGMPortable Graymap
PPMPortable Pixmap
SVGScalable Vector Graphicsd
TGATruevision Graphics Adapter
TIFFTagged Image File Format
WBMPWireless Bitmap
WEBPWebP
XBMX11 Bitmap
XPMX11 Pixmap

Note: Animated images are not supported.

If the width and height properties are not specified, the Image automatically uses the size of the loaded image. By default, specifying the width and height of the item 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.

See also dealing with image resources.

Example Usage

The following example shows the simplest usage of the Image type.

import QtQuick 2.15

Image {
    source: "qrc:/pics/qtlogo.png"
}


See also BorderImage, ColorizedImage, qulrcc, QUL_COMPRESSION, QUL_COPY_TO_RAM, QUL_OPTIMIZE_FOR_SCALE, QUL_OPTIMIZE_FOR_ROTATION, Dealing with image resources, Image optimizations, Managing Resources and Assets, and Image Caching.

Property Documentation

horizontalAlignment : enumeration

verticalAlignment : enumeration

Sets the horizontal and vertical alignment of the image. By default, the image is center aligned.

The valid values for horizontalAlignment are Image.AlignLeft, Image.AlignRight and Image.AlignHCenter. The valid values for verticalAlignment are Image.AlignTop, Image.AlignBottom and Image.AlignVCenter.


fillMode : enumeration

Set this property to define what happens when the source image has a different size than the item.

  • Image.Stretch - the image is scaled to fit
  • 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
  • Image.Pad - the image is not transformed

Stretch (default)
Image {
    width: 130; height: 100
    source: "qrc:/qtlogo.png"
}

PreserveAspectFit
Image {
    width: 130; height: 100
    fillMode: Image.PreserveAspectFit
    source: "qrc:/qtlogo.png"
}

PreserveAspectCrop
Image {
    width: 130; height: 100
    fillMode: Image.PreserveAspectCrop
    source: "qrc:/qtlogo.png"
    clip: true
}

Tile
Image {
    width: 120; height: 120
    fillMode: Image.Tile
    horizontalAlignment: Image.AlignLeft
    verticalAlignment: Image.AlignTop
    source: "qrc:/qtlogo.png"
}

TileVertically
Image {
    width: 120; height: 120
    fillMode: Image.TileVertically
    verticalAlignment: Image.AlignTop
    source: "qrc:/qtlogo.png"
}

TileHorizontally
Image {
    width: 120; height: 120
    fillMode: Image.TileHorizontally
    verticalAlignment: Image.AlignLeft
    source: "qrc:/qtlogo.png"
}

Note that clip is false by default which means that the item might paint outside its bounding rectangle even if the fillMode is set to PreserveAspectCrop.

Set QUL_OPTIMIZE_FOR_SCALE on images that are scaled to enable build-time optimizations for the resource.


rotation : real

This property holds the rotation of the item in degrees clockwise around its transformOrigin.

The default value is 0 degrees (that is, no rotation).

Rectangle {
    color: "blue"
    width: 100; height: 100
    Image {
        source: "red.png"
        x: 25; y: 25; width: 50; height: 50
        rotation: 30
    }
}

Note: This property is only generated when it has a binding. See Conditional availability of the scale, rotation, and transformOrigin properties.

This property was introduced in Qt Quick Ultralite 1.3.

See also Transform and Rotation.


scale : real

This property holds the scale factor for this item.

A scale of less than 1.0 renders the item smaller, whereas a scale greater than 1.0 renders the item larger. A negative scale causes the item to be mirrored when rendered.

The default value is 1.0.

Scaling is applied from the transformOrigin.

import QtQuick 2.15

Rectangle {
    color: "blue"
    width: 100; height: 100

    Rectangle {
        color: "green"
        width: 25; height: 25
    }

    Image {
        source: "red.png"
        x: 25; y: 25; width: 50; height: 50
        scale: 1.4
        transformOrigin: Item.TopLeft
    }
}

Note: This property is only generated when it has a binding. See Conditional availability of the scale, rotation, and transformOrigin properties.

This property was introduced in Qt Quick Ultralite 1.3.

See also Transform and Scale.


source : image

As the url QML basic type is not supported, there exists an another basic type called image which is the type of the Image object's source property.

Image accepts an absolute resource URI, for example "qrc:/images/map.png". The resource must have been compiled with qulrcc to be available.

If a string that is not known at compile-time will be set as a source Qt Quick Ultralite will perform run-time lookup to find the resource handle for the given string.

For example the following code results in runtime lookup:

Image {
    source: "qrc:/" + "foo.png"
}

A failed lookup resets the source property to an empty state in which nothing is rendered.

Note: Qt Quick Ultralite does not support dynamic resources. Every resource must be registered using the Qt Quick Ultralite resource system.

See also Managing Resources and Assets and Dealing with image resources.


transform : list<Transform>

This property holds the list of transformations to apply.

For more information see Transform.


transformOrigin : enumeration

This property holds the origin point around which scale and rotation transform.

Nine transform origins are available, as shown in the image below. The default transform origin is Item.Center.

This example rotates an image around its bottom-right corner.

Image {
    source: "myimage.png"
    transformOrigin: Item.BottomRight
    rotation: 45
}

To set an arbitrary transform origin point use the Scale or Rotation transform types with transform.

Note: This property is only generated when it has a binding. See Conditional availability of the scale, rotation, and transformOrigin properties.

This property was introduced in Qt Quick Ultralite 1.3.


Available under certain Qt licenses.
Find out more.