TextSelection QML Type | Qt Quick | Qt 6.11.1
Description: Represents a contiguous selection of text and its properties.

- Qt 6.11
- Qt Quick
- QML Types
- TextSelection
- Qt 6.11.1 Reference Documentation

# TextSelection QML Type

Represents a contiguous selection of text and its properties. More...

Import Statement: | `import QtQuick`
Since: | Qt 6.7

- List of all members, including inherited members

## Properties

- alignment : enumeration
- color : color
- document : TextDocument `(since 6.11)`
- font : color
- selectionEnd : int `(since 6.11)`
- selectionStart : int `(since 6.11)`
- text : string

## Methods

- void duplicate() `(since 6.11)`
- void linkTo(url destination) `(since 6.11)`
- void moveSelectionEnd(MoveOperation op, int n) `(since 6.11)`
- bool moveSelectionStart(MoveOperation op, int n) `(since 6.11)`

## Detailed Description

TextEdit.cursorSelection represents the range of text that is currently selected (for example by dragging the mouse). It can be used to query and modify the selected text, as well as properties in the character and block formats.

Additionally, since 6.11 it's possible to create explicit non-visual instances:

     TextEdit {
         id: textEdit

         TextSelection {
             id: sel1
         }
     }

`TextEdit.cursorSelection` and any explicit TextSelection instances can be used to query and modify the specified ranges of text, as well as properties in the character and block formats.

Note: This API is considered tech preview and may change or be removed in future versions of Qt.

See also TextEdit and QTextCursor.

## Property Documentation

### alignment : enumeration

The alignment of the block containing the selected text.

See also QTextBlockFormat::alignment().

### color : color

The foreground color of the selected text.

See also QTextCharFormat::foreground().

### document : TextDocument `[since 6.11]`

The QQuickTextDocument that contains the selected text.

This property was introduced in Qt 6.11.

See also QtQuick::TextEdit::textDocument.

### font : color

The font of the selected text.

See also QTextCharFormat::font().

### selectionEnd : int `[since 6.11]`

The position after the last character in the selection.

This property was introduced in Qt 6.11.

See also QtQuick::TextEdit::selectionEnd.

### selectionStart : int `[since 6.11]`

The position before the first character in the selection.

This property was introduced in Qt 6.11.

See also QtQuick::TextEdit::selectionStart.

### text : string

The selected text, without any rich text markup.

Setting this property replaces the selected text with the given string.

## Method Documentation

### `[since 6.11]` void duplicate()

Copy the selected text forward, keeping all formatting intact in the copy, and end with the copy as the selection.

For example if an entire line is selected, this function inserts a copy of that line immediately below, and selects the copy. If a word is is selected, this function copies it to the right and selects it.

This method was introduced in Qt 6.11.

### `[since 6.11]` void linkTo(url destination)

Create a hyperlink from the selected text to destination.

This method was introduced in Qt 6.11.

See also QTextCharFormat::setAnchorHref().

### `[since 6.11]` void moveSelectionEnd(MoveOperation op, int n)

Move selectionEnd n times according to op, which is one of the enum values as used in moveSelectionStart().

If moveSelectionStart() was called immediately before, `selectionEnd == selectionStart`, and this function moves it from there so that a range of text becomes selected.

This method was introduced in Qt 6.11.

See also QTextCursor::movePosition, QTextCursor::KeepAnchor, moveSelectionStart(), and QTextCursor::MoveOperation.

### `[since 6.11]` bool moveSelectionStart(MoveOperation op, int n)

Deselect text and move selectionStart n times according to op, which is one of the following enum values:

Constant | Description
--- | ---
`TextSelection.NoMove` | Keep the cursor where it is
`TextSelection.Start` | Move to the start of the document.
`TextSelection.StartOfLine` | Move to the start of the current line.
`TextSelection.StartOfBlock` | Move to the start of the current block.
`TextSelection.StartOfWord` | Move to the start of the current word.
`TextSelection.PreviousBlock` | Move to the start of the previous block.
`TextSelection.PreviousCharacter` | Move to the previous character.
`TextSelection.PreviousWord` | Move to the beginning of the previous word.
`TextSelection.Up` | Move up one line.
`TextSelection.Left` | Move left one character.
`TextSelection.WordLeft` | Move left one word.
`TextSelection.End` | Move to the end of the document.
`TextSelection.EndOfLine` | Move to the end of the current line.
`TextSelection.EndOfWord` | Move to the end of the current word.
`TextSelection.EndOfBlock` | Move to the end of the current block.
`TextSelection.NextBlock` | Move to the beginning of the next block.
`TextSelection.NextCharacter` | Move to the next character.
`TextSelection.NextWord` | Move to the next word.
`TextSelection.Down` | Move down one line.
`TextSelection.Right` | Move right one character.
`TextSelection.WordRight` | Move right one word.
`TextSelection.NextCell` | Move to the beginning of the next table cell inside the current table. If the current cell is the last cell in the row, the cursor will move to the first cell in the next row.
`TextSelection.PreviousCell` | Move to the beginning of the previous table cell inside the current table. If the current cell is the first cell in the row, the cursor will move to the last cell in the previous row.
`TextSelection.NextRow` | Move to the first new cell of the next row in the current table.
`TextSelection.PreviousRow` | Move to the last cell of the previous row in the current table.

Returns `true` if all operations were completed successfully; otherwise returns `false`.

This method was introduced in Qt 6.11.

See also QTextCursor::movePosition, QTextCursor::MoveAnchor, and QTextCursor::MoveOperation.