Skip to content

TextInput

The TextInput is a lower-level item that shows text and allows entering text. You should probably not use this directly, but instead use the LineEdit or TextEdit component.

When not part of a layout, its width and height defaults to 100% of the parent element.

The TextInput does not scroll automatically when the cursor is outside of the visible area. This is the responsibility of the enclosing widget to ensure using the cursor-position-changed callback.

export component Example inherits Window {
width: 270px;
height: 40px;
Rectangle {
clip: true;
TextInput {
text: "Edit me";
width: max(parent.width, self.preferred-width);
vertical-alignment: center;
private property <length> margin: 1rem;
cursor-position-changed(cursor-position) => {
if cursor-position.x + self.x < margin {
self.x = - cursor-position.x + margin;
} else if cursor-position.x + self.x > parent.width - margin - self.text-cursor-width {
self.x = parent.width - cursor-position.x - margin - self.text-cursor-width;
}
}
}
}
}
slint

brush default: depends on the style

The color of the text.

string default: ""

The name of the font family selected for rendering the text.

length default: 0px

The font size of the text.

int default: 0

The weight of the font. The values range from 100 (lightest) to 900 (thickest). 400 is the normal weight.

bool default: false

Whether or not the font face should be drawn italicized or not.

struct FontMetrics default: a struct with all default values

The design metrics of the font scaled to the font pixel size used by the element.

bool (out) default: false

TextInput sets this to true when it’s focused. Only then it receives KeyEvents.

enum TextHorizontalAlignment default: the first enum value

The horizontal alignment of the text.

enum InputType default: text

Use this to configure TextInput for editing special input, such as password fields.

length default: 0

The letter spacing allows changing the spacing between the glyphs. A positive value increases the spacing and a negative value decreases the distance.

length default: 0px

The height of the page used to compute how much to scroll when the user presses page up or page down.

bool default: false

When set to true, text editing via keyboard and mouse is disabled but selecting text is still enabled as well as editing text programmatically.

color default: a transparent color

The background color of the selection.

color default: a transparent color

The foreground color of the selection.

bool default: true

When set to true, the text is always rendered as a single line, regardless of new line separators in the text.

length default: provided at run-time by the selected widget style

The width of the text cursor.

string default: ""

The text rendered and editable by the user.

enum TextVerticalAlignment default: the first enum value

The vertical alignment of the text.

enum TextWrap default: no-wrap

The way the text input wraps. Only makes sense when single-line is false.

Call this function to focus the text input and make it receive future keyboard events.

Call this function to remove keyboard focus from this TextInput if it currently has the focus. See also FocusHandling.

Selects the text between two UTF-8 offsets.

Selects all text.

Clears the selection.

Copies the selected text to the clipboard.

Copies the selected text to the clipboard and removes it from the editable area.

Pastes the text content of the clipboard at the cursor position.

Invoked when the enter key is pressed.

The cursor was moved to the new (x, y) position described by the Point argument.

Invoked when the text has changed because the user modified it.

Invoked when a key is pressed, the argument is a KeyEvent struct. Use this callback to handle keys before TextInput does. Return accept to indicate that you’ve handled the event, or return reject to let TextInput handle it.

Invoked when a key is released, the argument is a KeyEvent struct. Use this callback to handle keys before TextInput does. Return accept to indicate that you’ve handled the event, or return reject to let TextInput handle it.

By default, TextInput elements have the following accessibility properties set:

  • accessible-role: text-input;
  • accessible-value: text;
  • accessible-enabled: enabled;
  • accessible-read-only: read-only;

© 2025 SixtyFPS GmbH