Image
An Image
can be used to represent an image loaded from a file. Supported image formats are:
Format | Extensions |
---|---|
PNG | .png |
JPEG | .jpg, .jpeg |
SVG | .svg |
Properties
colorize
type: brush
default: a transparent brush
When set, the image is used as an alpha mask and is drawn in the given color (or with the gradient).
horizontal-alignment
type: enum ImageHorizontalAlignment
default: the first enum value
ImageHorizontalAlignment
This enum specifies the horizontal alignment of the source image.
horizontal-tiling
type: enum ImageTiling
default: the first enum value
ImageTiling
This enum specifies how the source image will be tiled.
image-fit
type: enum ImageFit
default: `contain` when the `Image` element is part of a layout, `fill` otherwise
ImageFit
This enum defines how the source image shall fit into an Image
element.
fill
: Scales and stretches the source image to fit the width and height of theImage
element.contain
: The source image is scaled to fit into theImage
element’s dimension while preserving the aspect ratio.cover
: The source image is scaled to cover into theImage
element’s dimension while preserving the aspect ratio. If the aspect ratio of the source image doesn’t match the element’s one, then the image will be clipped to fit.preserve
: Preserves the size of the source image in logical pixels. The source image will still be scaled by the scale factor that applies to all elements in the window. Any extra space will be left blank.
image-rendering
type: enum ImageRendering
default: the first enum value
ImageRendering
This enum specifies how the source image will be scaled.
smooth
: The image is scaled with a linear interpolation algorithm.pixelated
: The image is scaled with the nearest neighbor algorithm.
Rotation
Rotates the text by the given angle around the specified origin point. The default origin point is the center of the element.
When these properties are set, the Image
can’t have children.
rotation-angle
type: angle
default: 0deg
rotation-origin-x
type: length
default: 0px
rotation-origin-y
type: length
default: 0px
source
properties
source
type: image
default: the empty image
The image
type is a reference to an image. It’s defined using the @image-url("...")
construct.
The address within the @image-url
function must be known at compile time.
Slint looks for images in the following places:
- The absolute path or the path relative to the current
.slint
file. - The include path used by the compiler to look up
.slint
files.
Access an image
’s source dimension using its source.width
and source.height
properties.
Use the @image-url("...")
macro to specify the location of the image.
source-clip-x
type: int
default: 0
source-clip-y
type: int
default: 0
source-clip-width
type: int
default: source.width - source.clip-x
source-clip-height
type: int
default: source.height - source.clip-y
vertical-alignment
type: enum ImageVerticalAlignment
default: the first enum value
ImageVerticalAlignment
This enum specifies the vertical alignment of the source image.