slint/docs/reference/src/language/widgets/textedit.md
Simon Hausmann 31767eb6ab Add a clear-focus()function on all elements that have a focus() function
This is the counter-part, which removes focus from the element if it's currently focused. The window - if focused - may still be focused towards the windowing system.
2024-04-26 11:09:11 +02:00

2.2 KiB

TextEdit

Similar to LineEdit, but can be used to enter several lines of text

Note: The current implementation only implement very few basic shortcut. More shortcut will be implemented in a future version: https://github.com/slint-ui/slint/issues/474

Properties

  • font-size (in length): the size of the font of the input text
  • text (in-out string): The text being edited
  • has-focus: (in_out bool): Set to true when the widget currently has the focus
  • enabled: (in bool): Defaults to true. When false, nothing can be entered
  • read-only (in bool): When set to true, text editing via keyboard and mouse is disabled but selecting text is still enabled as well as editing text programmatically (default value: false)
  • wrap (in enum TextWrap): The way the text wraps (default: word-wrap).
  • horizontal-alignment (in enum TextHorizontalAlignment): The horizontal alignment of the text.

Functions

  • focus() Call this function to focus the TextEdit and make it receive future keyboard events.
  • clear-focus() Call this function to remove keyboard focus from this TextEdit if it currently has the focus.
  • set-selection-offsets(int, int) Selects the text between two UTF-8 offsets.
  • select-all() Selects all text.
  • clear-selection() Clears the selection.
  • copy() Copies the selected text to the clipboard.
  • cut() Copies the selected text to the clipboard and removes it from the editable area.
  • paste() Pastes the text content of the clipboard at the cursor position.

Callbacks

  • edited(string): Emitted when the text has changed because the user modified it

Example

import { TextEdit } from "std-widgets.slint";
export component Example inherits Window {
    width: 200px;
    height: 200px;
    TextEdit {
        font-size: 14px;
        width: parent.width;
        height: parent.height;
        text: "Lorem ipsum dolor sit amet,\n consectetur adipisici elit";
    }
}