TextSelection QML Type

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

Import Statement: import QtQuick
Since: Qt 6.7

Properties

Methods

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:

ConstantDescription
TextSelection.NoMoveKeep the cursor where it is
TextSelection.StartMove to the start of the document.
TextSelection.StartOfLineMove to the start of the current line.
TextSelection.StartOfBlockMove to the start of the current block.
TextSelection.StartOfWordMove to the start of the current word.
TextSelection.PreviousBlockMove to the start of the previous block.
TextSelection.PreviousCharacterMove to the previous character.
TextSelection.PreviousWordMove to the beginning of the previous word.
TextSelection.UpMove up one line.
TextSelection.LeftMove left one character.
TextSelection.WordLeftMove left one word.
TextSelection.EndMove to the end of the document.
TextSelection.EndOfLineMove to the end of the current line.
TextSelection.EndOfWordMove to the end of the current word.
TextSelection.EndOfBlockMove to the end of the current block.
TextSelection.NextBlockMove to the beginning of the next block.
TextSelection.NextCharacterMove to the next character.
TextSelection.NextWordMove to the next word.
TextSelection.DownMove down one line.
TextSelection.RightMove right one character.
TextSelection.WordRightMove right one word.
TextSelection.NextCellMove 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.PreviousCellMove 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.NextRowMove to the first new cell of the next row in the current table.
TextSelection.PreviousRowMove 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.

© 2025 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.