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.
Example
Section titled “Example”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; } } } }}
Properties
Section titled “Properties” brush default: depends on the style
The color of the text.
font-family
Section titled “font-family” string default: ""
The name of the font family selected for rendering the text.
font-size
Section titled “font-size” length default: 0px
The font size of the text.
font-weight
Section titled “font-weight” int default: 0
The weight of the font. The values range from 100 (lightest) to 900 (thickest). 400 is the normal weight.
font-italic
Section titled “font-italic” bool default: false
Whether or not the font face should be drawn italicized or not.
font-metrics
Section titled “font-metrics” 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.
has-focus
Section titled “has-focus” bool (out)
default: false
TextInput
sets this to true
when it’s focused. Only then it receives KeyEvents.
horizontal-alignment
Section titled “horizontal-alignment” enum TextHorizontalAlignment default: the first enum value
The horizontal alignment of the text.
input-type
Section titled “input-type” enum InputType default: text
Use this to configure TextInput
for editing special input, such as password fields.
letter-spacing
Section titled “letter-spacing” 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.
page-height
Section titled “page-height” length default: 0px
The height of the page used to compute how much to scroll when the user presses page up or page down.
read-only
Section titled “read-only” 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.
selection-background-color
Section titled “selection-background-color” color default: a transparent color
The background color of the selection.
selection-foreground-color
Section titled “selection-foreground-color” color default: a transparent color
The foreground color of the selection.
single-line
Section titled “single-line” bool default: true
When set to true
, the text is always rendered as a single line, regardless of new line separators in the text.
text-cursor-width
Section titled “text-cursor-width” 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.
vertical-alignment
Section titled “vertical-alignment” 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.
Functions
Section titled “Functions”focus()
Section titled “focus()”Call this function to focus the text input and make it receive future keyboard events.
clear-focus()
Section titled “clear-focus()”Call this function to remove keyboard focus from this TextInput
if it currently has the focus. See also FocusHandling.
set-selection-offsets(int, int)
Section titled “set-selection-offsets(int, int)”Selects the text between two UTF-8 offsets.
select-all()
Section titled “select-all()”Selects all text.
clear-selection()
Section titled “clear-selection()”Clears the selection.
copy()
Section titled “copy()”Copies the selected text to the clipboard.
Copies the selected text to the clipboard and removes it from the editable area.
paste()
Section titled “paste()”Pastes the text content of the clipboard at the cursor position.
Callbacks
Section titled “Callbacks”accepted()
Section titled “accepted()”Invoked when the enter key is pressed.
cursor-position-changed(Point)
Section titled “cursor-position-changed(Point)”The cursor was moved to the new (x, y) position
described by the Point
argument.
edited()
Section titled “edited()”Invoked when the text has changed because the user modified it.
key-pressed(KeyEvent) -> EventResult
Section titled “key-pressed(KeyEvent) -> EventResult”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.
key-released(KeyEvent) -> EventResult
Section titled “key-released(KeyEvent) -> EventResult”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.
Accessibility
Section titled “Accessibility”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