---
<!-- Copyright © SixtyFPS GmbH <info@slint.dev> ; SPDX-License-Identifier: MIT -->
// cSpell: ignore Lorem ipsum dolor sit amet consectetur adipisici elit
title: TextEdit
description: TextEdit api.
---

import SlintProperty  from '/src/components/SlintProperty.astro';
import CodeSnippetMD from '/src/components/CodeSnippetMD.astro';
import Link from '/src/components/Link.astro';

<CodeSnippetMD imagePath="/src/assets/generated/std-widgets-textedit.png"  imageWidth="200" imageHeight="200"  imageAlt='std-widgets textedit example'>
```slint playground
import { TextEdit, VerticalBox } from "std-widgets.slint";
export component Example inherits Window {
    width: 200px;
    height: 200px;

    VerticalBox {
        TextEdit {
            font-size: 14px;
            text: "Lorem ipsum dolor sit amet,\n consectetur adipisici elit";
        }
    }
}
```
</CodeSnippetMD>

Similar to <Link type="LineEdit" />, but can be used to enter several lines of text

## Properties

### font-size
<SlintProperty propName="font-size" typeName="length" >
The size of the font of the input text.
</SlintProperty>

### text
<SlintProperty propName="text" typeName="string" propertyVisibility="in-out" >
The text being edited

```slint no-test 'text: "Initial text";'
TextEdit {
    text: "Initial text";
}
```
</SlintProperty>

### has-focus
<SlintProperty propName="has-focus" typeName="bool" propertyVisibility="in-out" >   
Set to true when the widget currently has the focus.
</SlintProperty>

### enabled
<SlintProperty propName="enabled" typeName="bool" defaultValue="true" >
When false, nothing can be entered.
</SlintProperty>

### read-only
<SlintProperty propName="read-only" typeName="bool" defaultValue="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.
</SlintProperty>

### `wrap` 
<SlintProperty propName="wrap" typeName="enum" enumName="TextWrap">
The way the text wraps (default: word-wrap).
</SlintProperty>

### `horizontal-alignment`
<SlintProperty propName="horizontal-alignment" typeName="enum" enumName='TextHorizontalAlignment' > 
The horizontal alignment of the text.
</SlintProperty>
-   **`placeholder-text`**: (_in_ _string_): A placeholder text being shown when there is no text in the edit field.

## 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. See also <Link type="FocusHandling" label="focus handling" />.
-   **`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

```slint no-test {2-4}
TextEdit {
    accepted(text) => {
        debug("Accepted: ", text);
    }
}
```

### rejected(string)
Invoked when the escape key is pressed.

```slint no-test {2-4}
TextEdit {
    rejected(text) => {
        debug("Rejected: ", text);
    }
}
```

