Skip to content

Macros

A macro invocation is @ followed by a macro name and, for most macros, arguments in parentheses. The macros are built into the language and cannot be declared. The recognized names are tr, image-url, linear-gradient, radial-gradient, conic-gradient, markdown, and keys. Any other name after @ is a compile error. As with all identifiers, - and _ are interchangeable, so image-url and image_url name the same macro.

A macro invocation is an expression and may appear wherever an expression of its result type is accepted. @children, described at the end, is not a macro but a placeholder.

@tr marks a string for translation and produces a value of type string. Its first argument is the format string, which must be a plain string literal. Optional trailing arguments are expressions substituted into the format string.

export component Example {
in property <string> name;
Text {
text: @tr("Hello, {}", name);
}
}
slint

See the translations guide for extracting and shipping the translations.

Each {} placeholder in the format string is replaced with the corresponding trailing argument in order. A placeholder may name a zero-based position, as in {0} or {1}, to select an argument explicitly. Positional and non-positional placeholders cannot be mixed in one format string; doing so is a compile error. A translation may use ordered placeholders even when the source string did not.

The literal characters { and } are written by doubling them, {{ and }}. An unescaped { or }, an unterminated placeholder, or a placeholder whose contents are neither empty, a number, nor n is a compile error. A placeholder count that exceeds the number of trailing arguments is a compile error.

A plural form selects between two format strings based on a count. It is written with | between the two literals and % before the count expression:

@tr("I have {n} item" | "I have {n} items" % count)
slint

Both sides of the | must be plain string literals. The expression after % is converted to int. The {n} placeholder refers to that expression and is valid only in a plural form; {n} without a plural form is a compile error. Other placeholders in a plural form still refer to the trailing arguments after the count.

export component Example inherits Text {
in property <int> score;
in property <int> name;
text: @tr("Hello {0}, you have one point" | "Hello {0}, you have {n} points" % score, name);
}
slint

A context disambiguates strings that share source text but differ in meaning. It is written as a plain string literal followed by => before the format string:

export component MenuItem {
property <string> name: @tr("Default Name"); // context: `MenuItem`
property <string> tooltip: @tr("ToolTip" => "ToolTip for {}", name); // context: `ToolTip`
}
slint

The context must be a plain string literal. Without one, the context defaults to the name of the enclosing component.

@image-url("...") produces a value of type image. The single required argument is a plain string literal; a template string or any other expression is a compile error.

The path is resolved at compile time. An absolute path is used as is; a relative path is resolved against the import path and then against the file that contains the invocation. An empty string produces an empty image. A string that starts with data: is treated as a data URL and embedded directly rather than resolved as a path.

An optional second argument nine-slice(...) marks the image for nine-slice scaling:

@image-url("foo.png", nine-slice(1 2 3 4))
slint

Its numbers are the border widths, separated by spaces, and must be one, two, or four integers without units. One value applies to all four borders; two values apply to the vertical and horizontal pairs; four values are top, right, bottom, left. A count other than one, two, or four, or a number carrying a unit, is a compile error.

@linear-gradient, @radial-gradient, @conic-gradient

Section titled “@linear-gradient, @radial-gradient, @conic-gradient”

The gradient macros produce a brush and take a comma-separated argument list of a leading geometry argument followed by color stops.

  • @linear-gradient(angle, ...) — the first argument is an angle, followed by color stops.
  • @radial-gradient(circle, ...) — the first argument must be the keyword circle; only circular radial gradients are supported. It may be followed by an optional radius length and an optional at x y center before the color stops.
  • @conic-gradient(...) — an optional from angle and an optional at x y center precede the color stops.
@linear-gradient(90deg, #3f87a6 0%, #ebf8e1 50%, #f69d3c 100%)
@radial-gradient(circle, #f00 0%, #0f0 50%, #00f 100%)
@conic-gradient(#f00 0deg, #0f0 120deg, #00f 240deg)
slint

For the color-stop syntax and the meaning of each geometry argument see Colors and Brushes.

@markdown("...") produces styled text parsed from Markdown. Each argument is a string literal; adjacent string literals are concatenated. An invocation with no string content is a compile error.

A string-template argument, "...\{ expr }...", interpolates an expression into the parsed text at that position. The private-use character reserved for interpolation cannot appear in the literal text; using it is a compile error.

@keys(...) produces a value of type keys, a key combination for key bindings. The argument is a +-separated sequence of at most one key and any number of modifiers, or empty.

  • The key is a single-grapheme string literal or a key name such as Return, written without the Key. prefix, and at most one may appear.
  • The modifiers are the identifiers Control, Shift, Alt, and Meta, each usable once.
  • Shift? and Alt? mark that modifier as ignored rather than required; a modifier and its ? form cannot both be present.
@keys(Control + Shift + "A")
@keys(Control + Alt + Return)
slint

A combination with modifiers but no key, a duplicated modifier, more than one key, a trailing +, or a platform-specific modifier name such as Ctrl, Cmd, Command, Win, or a right-side variant is a compile error.

@children is not a macro but a placeholder expression. It marks where a container component places the children passed to it.

It may appear at most once within an element, and at most once across an element hierarchy. It cannot appear inside a repeated, conditional, or match element. Each of these is a compile error.


© 2026 SixtyFPS GmbH