Skip to content

Operators

Slint has arithmetic, comparison, logical, and ternary operators, plus member access and indexing. Every operator requires operands of specific types; Slint applies no implicit coercions beyond the few listed here, and mismatched operand types are a compile error.

The following table lists all operators from loosest to tightest binding. Operators on the same row share a precedence level.

OperatorsDescriptionAssociativity
? :Ternary conditionalright
|| &&Logical or, logical andnon-associative
== != < > <= >=Comparisonnon-associative
+ -Addition/concatenation, subtractionleft
* /Multiplication, divisionleft
+ - ! (unary)Plus, negation, logical notprefix
. []Member access, indexingleft

Parentheses group a nested expression to override precedence. There is no modulo operator; use Math.mod instead. A % after a number is a unit (percent), not an operator. Slint has no bitwise, shift, increment, decrement, or assignment operators; a binding uses : and a two-way binding uses <=>.

Comparison operators are non-associative: writing a == b == c or a < b < c is an error, and the operands must be parenthesized to disambiguate. && and || are likewise non-associative with respect to each other: a && b || c is an error, and one side must be parenthesized.

export component Example {
in-out property <int> p: 1 * 2 + 3 * 4; // same as (1 * 2) + (3 * 4)
}
slint

The binary operators +, -, *, and / operate on numbers (int, float, percent) and on types that carry a unit (length, physical-length, duration, angle, rem).

  • + and - require both operands to be the same type, or one operand to be a plain number. Values of two different units cannot be added or subtracted.
  • * multiplies a value by a number, or two values with units, producing a unit product (for example 1px * 1px has type px²).
  • / divides a value by a number, or by another value. Dividing two values of the same unit yields a plain number, so self.width / 1px is the width as a float.
export component Example inherits Window {
in property <length> a;
in property <length> b;
out property <length> total: a + b * 2;
}
slint
export component Example {
in-out property <length> w: 10px + 2px; // ok, same unit
in-out property <length> h: 10px * 2; // ok, length times number
in-out property <float> r: self.w / self.h; // ok, length over length
}
slint

The + operator also concatenates strings: if either operand is a string, the result is a string. A number operand (int or float) is converted to its string form. No other type is coerced to string, so combining a string with, for example, a length is an error; use a string template to interpolate other types.

export component Example {
out property <string> s: "count: " + 42; // "count: 42"
}
slint

The operators ==, !=, <, >, <=, and >= compare two operands of a common type and produce a bool.

== and != test whether the operands are equal.

<, >, <=, and >= order numbers, unit-bearing types, and strings; ordering values of any other type is an error.

export component Example inherits Window {
in property <int> a;
in property <length> w;
in property <length> h;
out property <bool> equal: a == 0;
out property <bool> different: a != 0;
out property <bool> wider: w > h;
}
slint

The binary operators && and || combine two boolean operands into a boolean: && is true when both operands are true, || when either is.

The unary operator ! negates a boolean.

The operands must be bool; no other type is coerced to bool.

export component Example inherits Window {
in property <bool> a;
in property <bool> b;
out property <bool> both: a && b;
out property <bool> either: a || b;
out property <bool> neither: !a && !b;
}
slint

&& and || short-circuit: the right operand is evaluated only when the left does not already determine the result.

The prefix operators are +, -, and !.

+ and - apply to numbers and unit-bearing types, and ! applies to bool.

export component Example inherits Window {
in property <length> w;
in property <bool> flag;
out property <length> negated: -w;
out property <bool> toggled: !flag;
}
slint

condition ? value1 : value2 evaluates condition, a boolean, and yields value1 when it is true and value2 otherwise.

Both branches have the same type, which becomes the type of the whole expression.

A conditional associates to the right, so a ? b : c ? d : e groups as a ? b : (c ? d : e).

export component Example inherits Window {
in property <bool> on;
in property <color> active;
in property <color> idle;
out property <color> tint: on ? active : idle;
}
slint

A . accesses a property, function, or callback of an element by name, and a field of a struct value:

export component Example {
foo := Rectangle {
x: 42px;
}
x: foo.x;
}
slint

An [index] in square brackets accesses an element of an array by a zero-based integer index.


© 2026 SixtyFPS GmbH