Reference Overview
The Slint elements have many common properties, callbacks and behavior. This page describes these properties and their usage.
init()
Every element implicitly declares an init
callback. You can assign a code block to it that will be invoked when the
element is instantiated and after all properties are initialized with the value of their final binding. The order of
invocation is from inside to outside. The following example will print “first”, then “second”, and then “third”:
Don’t use this callback to initialize properties, because this violates the declarative principle.
Even though the init
callback exists on all components, it cannot be set from application code,
i.e. an on_init
function does not exist in the generated code. This is because the callback is invoked during the creation of the component, before you could call on_init
to actually set it.
While the init
callback can invoke other callbacks, e.g. one defined in a global
section, and
you can bind these in the backend, this doesn’t work for statically-created components, including
the window itself, because you need an instance to set the globals binding. But it is possible
to use this for dynamically created components (for example ones behind an if
):
Geometry
These properties are valid on all visible items:
x
length default: 0px
The position of the element relative to its parent.
y
length default: 0px
The position of the element relative to its parent.
z
float default: 0.0
Allows to specify a different order to stack the items with its siblings. The value must be a compile time constant.
absolute-position
struct Point default: a struct with all default values
Point
This structure represents a point with x and y coordinate
x
(length):y
(length):
The position of the element within the contained window.
width
length default: 0px
The width of the element. When set, this overrides the default width.
height
length default: 0px
The height of the element. When set, this overrides the default height.
opacity
float default: 1
A value between 0 and 1 (or a percentage) that is used to draw the element and its children with transparency. 0 is fully transparent (invisible), and 1 is fully opaque. The opacity is applied to the tree of child elements as if they were first drawn into an intermediate layer, and then the whole layer is rendered with this opacity.
visible
bool default: true
When set to false
, the element and all his children won’t be drawn and not react to mouse input.
The following example demonstrates the opacity
property with children. An opacity is applied to the red rectangle. Since the green rectangle is a child of the red one, you can see the gradient underneath it, but you can’t see the red rectangle through the green one.
Layout
These properties are valid on all visible items and can be used to specify constraints when used in layouts:
col
,row
,colspan
,rowspan
(in int): See GridLayout.horizontal-stretch
andvertical-stretch
(in-out float): Specify how much relative space these elements are stretching in a layout. When 0, this means that the elements won’t be stretched unless all elements are 0. Builtin widgets have a value of either 0 or 1.max-width
andmax-height
(in length): The maximum size of an elementmin-width
andmin-height
(in length): The minimum size of an elementpreferred-width
andpreferred-height
(in length): The preferred size of an element
Miscellaneous
-
cache-rendering-hint
(in bool): When set totrue
, this provides a hint to the renderer to cache the contents of the element and all the children into an intermediate cached layer. For complex sub-trees that rarely change this may speed up the rendering, at the expense of increased memory consumption. Not all rendering backends support this, so this is merely a hint. (default value:false
) -
dialog-button-role
(in enumDialogButtonRole
): Specify that this is a button in aDialog
.
Accessibility
Use the following accessible-
properties to make your items interact well with software like screen readers, braille terminals and other software to make your application accessible.
accessible-role
must be set in order to be able to set any other accessible property or callback.
accessible-role
(in enumAccessibleRole
): The role of the element. This property is mandatory to be able to use any other accessible properties. It should be set to a constant value. (default value:none
for most elements, buttext
for the Text element)accessible-checkable
(in bool): Whether the element is can be checked or not.accessible-checked
(in bool): Whether the element is checked or not. This maps to the “checked” state of checkboxes, radio buttons, and other widgets.accessible-description
(in string): The description for the current element.accessible-enabled
(in bool): Whether the element is enabled or not. This maps to the “enabled” state of most widgets. (default value:true
)accessible-label
(in string): The label for an interactive element. (default value: empty for most elements, or the value of thetext
property for Text elements)accessible-value-maximum
(in float): The maximum value of the item. This is used for example by spin boxes.accessible-value-minimum
(in float): The minimum value of the item.accessible-value-step
(in float) The smallest increment or decrement by which the current value can change. This corresponds to the step by which a handle on a slider can be dragged.accessible-value
(in string): The current value of the item.accessible-placeholder-text
(in string): A placeholder text to use when the item’s value is empty. Applies to text elements.accessible-selectable
(in bool): Whether the element can be selected or not.accessible-selected
(in bool): Whether the element is selected or not. This maps to the “is-selected” state of listview items.accessible-position-in-set
(in int): The index (starting from 0) of this element in a group of similar elements. Applies to list items, radio buttons and other elements.accessible-size-of-set
(in int): The total number of elements in a group. Applies to all elements of a group like list items, radio buttons and other elements, but not to their parent container like list views, radio button groups or other grouping elements.
You can also use the following callbacks that are going to be called by the accessibility framework:
accessible-action-default()
: Invoked when the default action for this widget is requested (eg: pressed for a button).accessible-action-set-value(string)
: Invoked when the user wants to change the accessible value.accessible-action-increment()
: Invoked when the user requests to increment the value.accessible-action-decrement()
: Invoked when the user requests to decrement the value.