Properties
All elements have properties. Built-in elements come with common properties such as color or dimensional properties. You can assign values or entire Expressions to them:
The default value of a property is the default value of the type.
For example a boolean property defaults to false
, an int
property to zero, etc.
In addition to the existing properties, define extra properties by specifying the type, the name, and optionally a default value:
Annotate extra properties with a qualifier that specifies how the property can be read and written:
private
(the default): The property can only be accessed from within the component.in
: The property is an input. It can be set and modified by the user of this component, for example through bindings or by assignment in callbacks. The component can provide a default binding, but it can’t overwrite it by assignmentout
: An output property that can only be set by the component. It’s read-only for the users of the components.in-out
: The property can be read and modified by everyone.
All properties declared at the top level of a component that aren’t private
are accessible from the outside when using a component as an element, or via the
language bindings from the business logic.
Change Callbacks
In Slint, it’s possible to define a callback that is invoked when a property’s value changes.
Note that these callbacks aren’t invoked immediately. Instead, they’re queued for invocation in the subsequent iteration of the event loop. A callback is invoked only if the property’s value has indeed changed. If a property’s value changes multiple times within the same event loop cycle, the callback is invoked only once. Additionally, if a property’s value changes and then reverts to its original state before the callback is executed, the callback won’t be invoked.
Warning: Altering properties during a change event in a way that could lead to the same property being affected is undefined behavior.
The above represents an infinite loop. Slint will break the loop after a few iterations. Consequently, if there’s a sequence of changed callbacks where one callback triggers another change callback, this sequence might break, and further callbacks won’t be invoked.
Therefore, it’s crucial not to overuse changed callbacks.
Warning: Utilize changed callbacks only when an alternative through binding isn’t feasible.
For instance, avoid doing this:
Instead, opt for:
Declarative bindings automatically manage dependencies. Using a changed callback forces immediate evaluation of bindings, which are typically evaluated lazily. This practice also compromises the purity of bindings, complicating edits via graphical editors. Accumulating excessive changed events can introduce issues and bugs, especially in scenarios involving loops, where a change callback modifies a property, potentially triggering changes to the same property.
© 2025 SixtyFPS GmbH