Struct qt_gui::QTextCursor

source ·
#[repr(C)]
pub struct QTextCursor { /* private fields */ }
Expand description

The QTextCursor class offers an API to access and modify QTextDocuments.

C++ class: QTextCursor.

C++ documentation:

The QTextCursor class offers an API to access and modify QTextDocuments.

Text cursors are objects that are used to access and modify the contents and underlying structure of text documents via a programming interface that mimics the behavior of a cursor in a text editor. QTextCursor contains information about both the cursor's position within a QTextDocument and any selection that it has made.

QTextCursor is modeled on the way a text cursor behaves in a text editor, providing a programmatic means of performing standard actions through the user interface. A document can be thought of as a single string of characters. The cursor's current position() then is always either between two consecutive characters in the string, or else before the very first character or after the very last character in the string. Documents can also contain tables, lists, images, and other objects in addition to text but, from the developer's point of view, the document can be treated as one long string. Some portions of that string can be considered to lie within particular blocks (e.g. paragraphs), or within a table's cell, or a list's item, or other structural elements. When we refer to "current character" we mean the character immediately before the cursor position() in the document. Similarly, the "current block" is the block that contains the cursor position().

A QTextCursor also has an anchor() position. The text that is between the anchor() and the position() is the selection. If anchor() == position() there is no selection.

The cursor position can be changed programmatically using setPosition() and movePosition(); the latter can also be used to select text. For selections see selectionStart(), selectionEnd(), hasSelection(), clearSelection(), and removeSelectedText().

If the position() is at the start of a block, atBlockStart() returns true; and if it is at the end of a block, atBlockEnd() returns true. The format of the current character is returned by charFormat(), and the format of the current block is returned by blockFormat().

Formatting can be applied to the current text document using the setCharFormat(), mergeCharFormat(), setBlockFormat() and mergeBlockFormat() functions. The 'set' functions will replace the cursor's current character or block format, while the 'merge' functions add the given format properties to the cursor's current format. If the cursor has a selection, the given format is applied to the current selection. Note that when only a part of a block is selected, the block format is applied to the entire block. The text at the current character position can be turned into a list using createList().

Deletions can be achieved using deleteChar(), deletePreviousChar(), and removeSelectedText().

Text strings can be inserted into the document with the insertText() function, blocks (representing new paragraphs) can be inserted with insertBlock().

Existing fragments of text can be inserted with insertFragment() but, if you want to insert pieces of text in various formats, it is usually still easier to use insertText() and supply a character format.

Various types of higher-level structure can also be inserted into the document with the cursor:

  • Lists are ordered sequences of block elements that are decorated with bullet points or symbols. These are inserted in a specified format with insertList().
  • Tables are inserted with the insertTable() function, and can be given an optional format. These contain an array of cells that can be traversed using the cursor.
  • Inline images are inserted with insertImage(). The image to be used can be specified in an image format, or by name.
  • Frames are inserted by calling insertFrame() with a specified format.

Actions can be grouped (i.e. treated as a single action for undo/redo) using beginEditBlock() and endEditBlock().

Cursor movements are limited to valid cursor positions. In Latin writing this is between any two consecutive characters in the text, before the first character, or after the last character. In some other writing systems cursor movements are limited to "clusters" (e.g. a syllable in Devanagari, or a base letter plus diacritics). Functions such as movePosition() and deleteChar() limit cursor movement to these valid positions.

Implementations§

source§

impl QTextCursor

source

pub unsafe fn anchor(&self) -> c_int

Returns the anchor position; this is the same as position() unless there is a selection in which case position() marks one end of the selection and anchor() marks the other end. Just like the cursor position, the anchor position is between characters.

Calls C++ function: int QTextCursor::anchor() const.

C++ documentation:

Returns the anchor position; this is the same as position() unless there is a selection in which case position() marks one end of the selection and anchor() marks the other end. Just like the cursor position, the anchor position is between characters.

See also position(), setPosition(), movePosition(), selectionStart(), and selectionEnd().

source

pub unsafe fn at_block_end(&self) -> bool

Returns true if the cursor is at the end of a block; otherwise returns false.

Calls C++ function: bool QTextCursor::atBlockEnd() const.

C++ documentation:

Returns true if the cursor is at the end of a block; otherwise returns false.

See also atBlockStart() and atEnd().

source

pub unsafe fn at_block_start(&self) -> bool

Returns true if the cursor is at the start of a block; otherwise returns false.

Calls C++ function: bool QTextCursor::atBlockStart() const.

C++ documentation:

Returns true if the cursor is at the start of a block; otherwise returns false.

See also atBlockEnd() and atStart().

source

pub unsafe fn at_end(&self) -> bool

Returns true if the cursor is at the end of the document; otherwise returns false.

Calls C++ function: bool QTextCursor::atEnd() const.

C++ documentation:

Returns true if the cursor is at the end of the document; otherwise returns false.

This function was introduced in Qt 4.6.

See also atStart() and atBlockEnd().

source

pub unsafe fn at_start(&self) -> bool

Returns true if the cursor is at the start of the document; otherwise returns false.

Calls C++ function: bool QTextCursor::atStart() const.

C++ documentation:

Returns true if the cursor is at the start of the document; otherwise returns false.

See also atBlockStart() and atEnd().

source

pub unsafe fn begin_edit_block(&self)

Indicates the start of a block of editing operations on the document that should appear as a single operation from an undo/redo point of view.

Calls C++ function: void QTextCursor::beginEditBlock().

C++ documentation:

Indicates the start of a block of editing operations on the document that should appear as a single operation from an undo/redo point of view.

For example:

QTextCursor cursor(textDocument); cursor.beginEditBlock(); cursor.insertText(“Hello”); cursor.insertText(“World”); cursor.endEditBlock();

textDocument->undo();

The call to undo() will cause both insertions to be undone, causing both "World" and "Hello" to be removed.

It is possible to nest calls to beginEditBlock and endEditBlock. The top-most pair will determine the scope of the undo/redo operation.

See also endEditBlock().

source

pub unsafe fn block(&self) -> CppBox<QTextBlock>

Returns the block that contains the cursor.

Calls C++ function: QTextBlock QTextCursor::block() const.

C++ documentation:

Returns the block that contains the cursor.

source

pub unsafe fn block_char_format(&self) -> CppBox<QTextCharFormat>

Returns the block character format of the block the cursor is in.

Calls C++ function: QTextCharFormat QTextCursor::blockCharFormat() const.

C++ documentation:

Returns the block character format of the block the cursor is in.

The block char format is the format used when inserting text at the beginning of an empty block.

See also setBlockCharFormat().

source

pub unsafe fn block_format(&self) -> CppBox<QTextBlockFormat>

Returns the block format of the block the cursor is in.

Calls C++ function: QTextBlockFormat QTextCursor::blockFormat() const.

C++ documentation:

Returns the block format of the block the cursor is in.

See also setBlockFormat() and charFormat().

source

pub unsafe fn block_number(&self) -> c_int

Returns the number of the block the cursor is in, or 0 if the cursor is invalid.

Calls C++ function: int QTextCursor::blockNumber() const.

C++ documentation:

Returns the number of the block the cursor is in, or 0 if the cursor is invalid.

Note that this function only makes sense in documents without complex objects such as tables or frames.

This function was introduced in Qt 4.2.

source

pub unsafe fn char_format(&self) -> CppBox<QTextCharFormat>

Returns the format of the character immediately before the cursor position(). If the cursor is positioned at the beginning of a text block that is not empty then the format of the character immediately after the cursor is returned.

Calls C++ function: QTextCharFormat QTextCursor::charFormat() const.

C++ documentation:

Returns the format of the character immediately before the cursor position(). If the cursor is positioned at the beginning of a text block that is not empty then the format of the character immediately after the cursor is returned.

See also setCharFormat(), insertText(), and blockFormat().

source

pub unsafe fn clear_selection(&self)

Clears the current selection by setting the anchor to the cursor position.

Calls C++ function: void QTextCursor::clearSelection().

C++ documentation:

Clears the current selection by setting the anchor to the cursor position.

Note that it does not delete the text of the selection.

See also removeSelectedText() and hasSelection().

source

pub unsafe fn column_number(&self) -> c_int

Returns the position of the cursor within its containing line.

Calls C++ function: int QTextCursor::columnNumber() const.

C++ documentation:

Returns the position of the cursor within its containing line.

Note that this is the column number relative to a wrapped line, not relative to the block (i.e. the paragraph).

You probably want to call positionInBlock() instead.

This function was introduced in Qt 4.2.

See also positionInBlock().

source

pub unsafe fn copy_from( &self, other: impl CastInto<Ref<QTextCursor>> ) -> Ref<QTextCursor>

Makes a copy of cursor and assigns it to this QTextCursor. Note that QTextCursor is an implicitly shared class.

Calls C++ function: QTextCursor& QTextCursor::operator=(const QTextCursor& other).

C++ documentation:

Makes a copy of cursor and assigns it to this QTextCursor. Note that QTextCursor is an implicitly shared class.

source

pub unsafe fn create_list_q_text_list_format( &self, format: impl CastInto<Ref<QTextListFormat>> ) -> QPtr<QTextList>

Creates and returns a new list with the given format, and makes the current paragraph the cursor is in the first list item.

Calls C++ function: QTextList* QTextCursor::createList(const QTextListFormat& format).

C++ documentation:

Creates and returns a new list with the given format, and makes the current paragraph the cursor is in the first list item.

See also insertList() and currentList().

source

pub unsafe fn create_list_style(&self, style: Style) -> QPtr<QTextList>

This is an overloaded function.

Calls C++ function: QTextList* QTextCursor::createList(QTextListFormat::Style style).

C++ documentation:

This is an overloaded function.

Creates and returns a new list with the given style, making the cursor's current paragraph the first list item.

The style to be used is defined by the QTextListFormat::Style enum.

See also insertList() and currentList().

source

pub unsafe fn current_frame(&self) -> QPtr<QTextFrame>

Returns a pointer to the current frame. Returns 0 if the cursor is invalid.

Calls C++ function: QTextFrame* QTextCursor::currentFrame() const.

C++ documentation:

Returns a pointer to the current frame. Returns 0 if the cursor is invalid.

See also insertFrame().

source

pub unsafe fn current_list(&self) -> QPtr<QTextList>

Returns the current list if the cursor position() is inside a block that is part of a list; otherwise returns 0.

Calls C++ function: QTextList* QTextCursor::currentList() const.

C++ documentation:

Returns the current list if the cursor position() is inside a block that is part of a list; otherwise returns 0.

See also insertList() and createList().

source

pub unsafe fn current_table(&self) -> QPtr<QTextTable>

Returns a pointer to the current table if the cursor position() is inside a block that is part of a table; otherwise returns 0.

Calls C++ function: QTextTable* QTextCursor::currentTable() const.

C++ documentation:

Returns a pointer to the current table if the cursor position() is inside a block that is part of a table; otherwise returns 0.

See also insertTable().

source

pub unsafe fn delete_char(&self)

If there is no selected text, deletes the character at the current cursor position; otherwise deletes the selected text.

Calls C++ function: void QTextCursor::deleteChar().

C++ documentation:

If there is no selected text, deletes the character at the current cursor position; otherwise deletes the selected text.

See also deletePreviousChar(), hasSelection(), and clearSelection().

source

pub unsafe fn delete_previous_char(&self)

If there is no selected text, deletes the character before the current cursor position; otherwise deletes the selected text.

Calls C++ function: void QTextCursor::deletePreviousChar().

C++ documentation:

If there is no selected text, deletes the character before the current cursor position; otherwise deletes the selected text.

See also deleteChar(), hasSelection(), and clearSelection().

source

pub unsafe fn document(&self) -> QPtr<QTextDocument>

Returns the document this cursor is associated with.

Calls C++ function: QTextDocument* QTextCursor::document() const.

C++ documentation:

Returns the document this cursor is associated with.

This function was introduced in Qt 4.5.

source

pub unsafe fn end_edit_block(&self)

Indicates the end of a block of editing operations on the document that should appear as a single operation from an undo/redo point of view.

Calls C++ function: void QTextCursor::endEditBlock().

C++ documentation:

Indicates the end of a block of editing operations on the document that should appear as a single operation from an undo/redo point of view.

See also beginEditBlock().

source

pub unsafe fn has_complex_selection(&self) -> bool

Returns true if the cursor contains a selection that is not simply a range from selectionStart() to selectionEnd(); otherwise returns false.

Calls C++ function: bool QTextCursor::hasComplexSelection() const.

C++ documentation:

Returns true if the cursor contains a selection that is not simply a range from selectionStart() to selectionEnd(); otherwise returns false.

Complex selections are ones that span at least two cells in a table; their extent is specified by selectedTableCells().

source

pub unsafe fn has_selection(&self) -> bool

Returns true if the cursor contains a selection; otherwise returns false.

Calls C++ function: bool QTextCursor::hasSelection() const.

C++ documentation:

Returns true if the cursor contains a selection; otherwise returns false.

source

pub unsafe fn insert_block_0a(&self)

Inserts a new empty block at the cursor position() with the current blockFormat() and charFormat().

Calls C++ function: void QTextCursor::insertBlock().

C++ documentation:

Inserts a new empty block at the cursor position() with the current blockFormat() and charFormat().

See also setBlockFormat().

source

pub unsafe fn insert_block_1a( &self, format: impl CastInto<Ref<QTextBlockFormat>> )

This is an overloaded function.

Calls C++ function: void QTextCursor::insertBlock(const QTextBlockFormat& format).

C++ documentation:

This is an overloaded function.

Inserts a new empty block at the cursor position() with block format format and the current charFormat() as block char format.

See also setBlockFormat().

source

pub unsafe fn insert_block_2a( &self, format: impl CastInto<Ref<QTextBlockFormat>>, char_format: impl CastInto<Ref<QTextCharFormat>> )

This is an overloaded function.

Calls C++ function: void QTextCursor::insertBlock(const QTextBlockFormat& format, const QTextCharFormat& charFormat).

C++ documentation:

This is an overloaded function.

Inserts a new empty block at the cursor position() with block format format and charFormat as block char format.

See also setBlockFormat().

source

pub unsafe fn insert_fragment( &self, fragment: impl CastInto<Ref<QTextDocumentFragment>> )

Inserts the text fragment at the current position().

Calls C++ function: void QTextCursor::insertFragment(const QTextDocumentFragment& fragment).

C++ documentation:

Inserts the text fragment at the current position().

source

pub unsafe fn insert_frame( &self, format: impl CastInto<Ref<QTextFrameFormat>> ) -> QPtr<QTextFrame>

Inserts a frame with the given format at the current cursor position(), moves the cursor position() inside the frame, and returns the frame.

Calls C++ function: QTextFrame* QTextCursor::insertFrame(const QTextFrameFormat& format).

C++ documentation:

Inserts a frame with the given format at the current cursor position(), moves the cursor position() inside the frame, and returns the frame.

If the cursor holds a selection, the whole selection is moved inside the frame.

See also hasSelection().

source

pub unsafe fn insert_html(&self, html: impl CastInto<Ref<QString>>)

Inserts the text html at the current position(). The text is interpreted as HTML.

Calls C++ function: void QTextCursor::insertHtml(const QString& html).

C++ documentation:

Inserts the text html at the current position(). The text is interpreted as HTML.

Note: When using this function with a style sheet, the style sheet will only apply to the current block in the document. In order to apply a style sheet throughout a document, use QTextDocument::setDefaultStyleSheet() instead.

This function was introduced in Qt 4.2.

source

pub unsafe fn insert_image_q_text_image_format_position( &self, format: impl CastInto<Ref<QTextImageFormat>>, alignment: Position )

This is an overloaded function.

Calls C++ function: void QTextCursor::insertImage(const QTextImageFormat& format, QTextFrameFormat::Position alignment).

C++ documentation:

This is an overloaded function.

Inserts the image defined by the given format at the cursor's current position with the specified alignment.

This function was introduced in Qt 4.2.

See also position().

source

pub unsafe fn insert_image_q_text_image_format( &self, format: impl CastInto<Ref<QTextImageFormat>> )

Inserts the image defined by format at the current position().

Calls C++ function: void QTextCursor::insertImage(const QTextImageFormat& format).

C++ documentation:

Inserts the image defined by format at the current position().

source

pub unsafe fn insert_image_q_string(&self, name: impl CastInto<Ref<QString>>)

This is an overloaded function.

Calls C++ function: void QTextCursor::insertImage(const QString& name).

C++ documentation:

This is an overloaded function.

Convenience method for inserting the image with the given name at the current position().

QImage img = ... textDocument->addResource(QTextDocument::ImageResource, QUrl(“myimage”), img); cursor.insertImage(“myimage”);

source

pub unsafe fn insert_image_q_image_q_string( &self, image: impl CastInto<Ref<QImage>>, name: impl CastInto<Ref<QString>> )

This is an overloaded function.

Calls C++ function: void QTextCursor::insertImage(const QImage& image, const QString& name = …).

C++ documentation:

This is an overloaded function.

Convenience function for inserting the given image with an optional name at the current position().

This function was introduced in Qt 4.5.

source

pub unsafe fn insert_image_q_image(&self, image: impl CastInto<Ref<QImage>>)

This is an overloaded function.

Calls C++ function: void QTextCursor::insertImage(const QImage& image).

C++ documentation:

This is an overloaded function.

Convenience function for inserting the given image with an optional name at the current position().

This function was introduced in Qt 4.5.

source

pub unsafe fn insert_list_q_text_list_format( &self, format: impl CastInto<Ref<QTextListFormat>> ) -> QPtr<QTextList>

Inserts a new block at the current position and makes it the first list item of a newly created list with the given format. Returns the created list.

Calls C++ function: QTextList* QTextCursor::insertList(const QTextListFormat& format).

C++ documentation:

Inserts a new block at the current position and makes it the first list item of a newly created list with the given format. Returns the created list.

See also currentList(), createList(), and insertBlock().

source

pub unsafe fn insert_list_style(&self, style: Style) -> QPtr<QTextList>

This is an overloaded function.

Calls C++ function: QTextList* QTextCursor::insertList(QTextListFormat::Style style).

C++ documentation:

This is an overloaded function.

Inserts a new block at the current position and makes it the first list item of a newly created list with the given style. Returns the created list.

See also currentList(), createList(), and insertBlock().

source

pub unsafe fn insert_table_3a( &self, rows: c_int, cols: c_int, format: impl CastInto<Ref<QTextTableFormat>> ) -> QPtr<QTextTable>

Creates a new table with the given number of rows and columns in the specified format, inserts it at the current cursor position() in the document, and returns the table object. The cursor is moved to the beginning of the first cell.

Calls C++ function: QTextTable* QTextCursor::insertTable(int rows, int cols, const QTextTableFormat& format).

C++ documentation:

Creates a new table with the given number of rows and columns in the specified format, inserts it at the current cursor position() in the document, and returns the table object. The cursor is moved to the beginning of the first cell.

There must be at least one row and one column in the table.

See also currentTable().

source

pub unsafe fn insert_table_2a( &self, rows: c_int, cols: c_int ) -> QPtr<QTextTable>

This is an overloaded function.

Calls C++ function: QTextTable* QTextCursor::insertTable(int rows, int cols).

C++ documentation:

This is an overloaded function.

Creates a new table with the given number of rows and columns, inserts it at the current cursor position() in the document, and returns the table object. The cursor is moved to the beginning of the first cell.

There must be at least one row and one column in the table.

See also currentTable().

source

pub unsafe fn insert_text_1a(&self, text: impl CastInto<Ref<QString>>)

Inserts text at the current position, using the current character format.

Calls C++ function: void QTextCursor::insertText(const QString& text).

C++ documentation:

Inserts text at the current position, using the current character format.

If there is a selection, the selection is deleted and replaced by text, for example:

cursor.clearSelection(); cursor.movePosition(QTextCursor::NextWord, QTextCursor::KeepAnchor); cursor.insertText(“Hello World”);

This clears any existing selection, selects the word at the cursor (i.e. from position() forward), and replaces the selection with the phrase "Hello World".

Any ASCII linefeed characters (\n) in the inserted text are transformed into unicode block separators, corresponding to insertBlock() calls.

See also charFormat() and hasSelection().

source

pub unsafe fn insert_text_2a( &self, text: impl CastInto<Ref<QString>>, format: impl CastInto<Ref<QTextCharFormat>> )

This is an overloaded function.

Calls C++ function: void QTextCursor::insertText(const QString& text, const QTextCharFormat& format).

C++ documentation:

This is an overloaded function.

Inserts text at the current position with the given format.

source

pub unsafe fn is_copy_of(&self, other: impl CastInto<Ref<QTextCursor>>) -> bool

Returns true if this cursor and other are copies of each other, i.e. one of them was created as a copy of the other and neither has moved since. This is much stricter than equality.

Calls C++ function: bool QTextCursor::isCopyOf(const QTextCursor& other) const.

C++ documentation:

Returns true if this cursor and other are copies of each other, i.e. one of them was created as a copy of the other and neither has moved since. This is much stricter than equality.

See also operator=() and operator==().

source

pub unsafe fn is_null(&self) -> bool

Returns true if the cursor is null; otherwise returns false. A null cursor is created by the default constructor.

Calls C++ function: bool QTextCursor::isNull() const.

C++ documentation:

Returns true if the cursor is null; otherwise returns false. A null cursor is created by the default constructor.

source

pub unsafe fn join_previous_edit_block(&self)

Like beginEditBlock() indicates the start of a block of editing operations that should appear as a single operation for undo/redo. However unlike beginEditBlock() it does not start a new block but reverses the previous call to endEditBlock() and therefore makes following operations part of the previous edit block created.

Calls C++ function: void QTextCursor::joinPreviousEditBlock().

C++ documentation:

Like beginEditBlock() indicates the start of a block of editing operations that should appear as a single operation for undo/redo. However unlike beginEditBlock() it does not start a new block but reverses the previous call to endEditBlock() and therefore makes following operations part of the previous edit block created.

For example:

QTextCursor cursor(textDocument); cursor.beginEditBlock(); cursor.insertText(“Hello”); cursor.insertText(“World”); cursor.endEditBlock();

...

cursor.joinPreviousEditBlock(); cursor.insertText(“Hey”); cursor.endEditBlock();

textDocument->undo();

The call to undo() will cause all three insertions to be undone.

See also beginEditBlock() and endEditBlock().

source

pub unsafe fn keep_position_on_insert(&self) -> bool

Returns whether the cursor should keep its current position when text gets inserted at the position of the cursor.

Calls C++ function: bool QTextCursor::keepPositionOnInsert() const.

C++ documentation:

Returns whether the cursor should keep its current position when text gets inserted at the position of the cursor.

The default is false;

This function was introduced in Qt 4.7.

See also setKeepPositionOnInsert().

source

pub unsafe fn merge_block_char_format( &self, modifier: impl CastInto<Ref<QTextCharFormat>> )

Modifies the block char format of the current block (or all blocks that are contained in the selection) with the block format specified by modifier.

Calls C++ function: void QTextCursor::mergeBlockCharFormat(const QTextCharFormat& modifier).

C++ documentation:

Modifies the block char format of the current block (or all blocks that are contained in the selection) with the block format specified by modifier.

See also setBlockCharFormat().

source

pub unsafe fn merge_block_format( &self, modifier: impl CastInto<Ref<QTextBlockFormat>> )

Modifies the block format of the current block (or all blocks that are contained in the selection) with the block format specified by modifier.

Calls C++ function: void QTextCursor::mergeBlockFormat(const QTextBlockFormat& modifier).

C++ documentation:

Modifies the block format of the current block (or all blocks that are contained in the selection) with the block format specified by modifier.

See also setBlockFormat() and blockFormat().

source

pub unsafe fn merge_char_format( &self, modifier: impl CastInto<Ref<QTextCharFormat>> )

Merges the cursor's current character format with the properties described by format modifier. If the cursor has a selection, this function applies all the properties set in modifier to all the character formats that are part of the selection.

Calls C++ function: void QTextCursor::mergeCharFormat(const QTextCharFormat& modifier).

C++ documentation:

Merges the cursor’s current character format with the properties described by format modifier. If the cursor has a selection, this function applies all the properties set in modifier to all the character formats that are part of the selection.

See also hasSelection() and setCharFormat().

source

pub unsafe fn move_position_3a( &self, op: MoveOperation, arg2: MoveMode, n: c_int ) -> bool

Moves the cursor by performing the given operation n times, using the specified mode, and returns true if all operations were completed successfully; otherwise returns false.

Calls C++ function: bool QTextCursor::movePosition(QTextCursor::MoveOperation op, QTextCursor::MoveMode arg2 = …, int n = …).

C++ documentation:

Moves the cursor by performing the given operation n times, using the specified mode, and returns true if all operations were completed successfully; otherwise returns false.

For example, if this function is repeatedly used to seek to the end of the next word, it will eventually fail when the end of the document is reached.

By default, the move operation is performed once (n = 1).

If mode is KeepAnchor, the cursor selects the text it moves over. This is the same effect that the user achieves when they hold down the Shift key and move the cursor with the cursor keys.

See also setVisualNavigation().

source

pub unsafe fn move_position_2a(&self, op: MoveOperation, arg2: MoveMode) -> bool

Moves the cursor by performing the given operation n times, using the specified mode, and returns true if all operations were completed successfully; otherwise returns false.

Calls C++ function: bool QTextCursor::movePosition(QTextCursor::MoveOperation op, QTextCursor::MoveMode arg2 = …).

C++ documentation:

Moves the cursor by performing the given operation n times, using the specified mode, and returns true if all operations were completed successfully; otherwise returns false.

For example, if this function is repeatedly used to seek to the end of the next word, it will eventually fail when the end of the document is reached.

By default, the move operation is performed once (n = 1).

If mode is KeepAnchor, the cursor selects the text it moves over. This is the same effect that the user achieves when they hold down the Shift key and move the cursor with the cursor keys.

See also setVisualNavigation().

source

pub unsafe fn move_position_1a(&self, op: MoveOperation) -> bool

Moves the cursor by performing the given operation n times, using the specified mode, and returns true if all operations were completed successfully; otherwise returns false.

Calls C++ function: bool QTextCursor::movePosition(QTextCursor::MoveOperation op).

C++ documentation:

Moves the cursor by performing the given operation n times, using the specified mode, and returns true if all operations were completed successfully; otherwise returns false.

For example, if this function is repeatedly used to seek to the end of the next word, it will eventually fail when the end of the document is reached.

By default, the move operation is performed once (n = 1).

If mode is KeepAnchor, the cursor selects the text it moves over. This is the same effect that the user achieves when they hold down the Shift key and move the cursor with the cursor keys.

See also setVisualNavigation().

source

pub unsafe fn new() -> CppBox<QTextCursor>

Constructs a null cursor.

Calls C++ function: [constructor] void QTextCursor::QTextCursor().

C++ documentation:

Constructs a null cursor.

source

pub unsafe fn from_q_text_document( document: impl CastInto<Ptr<QTextDocument>> ) -> CppBox<QTextCursor>

Constructs a cursor pointing to the beginning of the document.

Calls C++ function: [constructor] void QTextCursor::QTextCursor(QTextDocument* document).

C++ documentation:

Constructs a cursor pointing to the beginning of the document.

source

pub unsafe fn from_q_text_frame( frame: impl CastInto<Ptr<QTextFrame>> ) -> CppBox<QTextCursor>

Constructs a cursor pointing to the beginning of the frame.

Calls C++ function: [constructor] void QTextCursor::QTextCursor(QTextFrame* frame).

C++ documentation:

Constructs a cursor pointing to the beginning of the frame.

source

pub unsafe fn from_q_text_block( block: impl CastInto<Ref<QTextBlock>> ) -> CppBox<QTextCursor>

Constructs a cursor pointing to the beginning of the block.

Calls C++ function: [constructor] void QTextCursor::QTextCursor(const QTextBlock& block).

C++ documentation:

Constructs a cursor pointing to the beginning of the block.

source

pub unsafe fn new_copy( cursor: impl CastInto<Ref<QTextCursor>> ) -> CppBox<QTextCursor>

Constructs a new cursor that is a copy of cursor.

Calls C++ function: [constructor] void QTextCursor::QTextCursor(const QTextCursor& cursor).

C++ documentation:

Constructs a new cursor that is a copy of cursor.

source

pub unsafe fn position(&self) -> c_int

Returns the absolute position of the cursor within the document. The cursor is positioned between characters.

Calls C++ function: int QTextCursor::position() const.

C++ documentation:

Returns the absolute position of the cursor within the document. The cursor is positioned between characters.

See also setPosition(), movePosition(), anchor(), and positionInBlock().

source

pub unsafe fn position_in_block(&self) -> c_int

Returns the relative position of the cursor within the block. The cursor is positioned between characters.

Calls C++ function: int QTextCursor::positionInBlock() const.

C++ documentation:

Returns the relative position of the cursor within the block. The cursor is positioned between characters.

This is equivalent to position() - block().position().

This function was introduced in Qt 4.7.

See also position().

source

pub unsafe fn remove_selected_text(&self)

If there is a selection, its content is deleted; otherwise does nothing.

Calls C++ function: void QTextCursor::removeSelectedText().

C++ documentation:

If there is a selection, its content is deleted; otherwise does nothing.

See also hasSelection().

source

pub unsafe fn select(&self, selection: SelectionType)

Selects text in the document according to the given selection.

Calls C++ function: void QTextCursor::select(QTextCursor::SelectionType selection).

C++ documentation:

Selects text in the document according to the given selection.

source

pub unsafe fn selected_table_cells( &self, first_row: *mut c_int, num_rows: *mut c_int, first_column: *mut c_int, num_columns: *mut c_int )

If the selection spans over table cells, firstRow is populated with the number of the first row in the selection, firstColumn with the number of the first column in the selection, and numRows and numColumns with the number of rows and columns in the selection. If the selection does not span any table cells the results are harmless but undefined.

Calls C++ function: void QTextCursor::selectedTableCells(int* firstRow, int* numRows, int* firstColumn, int* numColumns) const.

C++ documentation:

If the selection spans over table cells, firstRow is populated with the number of the first row in the selection, firstColumn with the number of the first column in the selection, and numRows and numColumns with the number of rows and columns in the selection. If the selection does not span any table cells the results are harmless but undefined.

source

pub unsafe fn selected_text(&self) -> CppBox<QString>

Returns the current selection's text (which may be empty). This only returns the text, with no rich text formatting information. If you want a document fragment (i.e. formatted rich text) use selection() instead.

Calls C++ function: QString QTextCursor::selectedText() const.

C++ documentation:

Returns the current selection’s text (which may be empty). This only returns the text, with no rich text formatting information. If you want a document fragment (i.e. formatted rich text) use selection() instead.

Note: If the selection obtained from an editor spans a line break, the text will contain a Unicode U+2029 paragraph separator character instead of a newline \n character. Use QString::replace() to replace these characters with newlines.

source

pub unsafe fn selection(&self) -> CppBox<QTextDocumentFragment>

Returns the current selection (which may be empty) with all its formatting information. If you just want the selected text (i.e. plain text) use selectedText() instead.

Calls C++ function: QTextDocumentFragment QTextCursor::selection() const.

C++ documentation:

Returns the current selection (which may be empty) with all its formatting information. If you just want the selected text (i.e. plain text) use selectedText() instead.

Note: Unlike QTextDocumentFragment::toPlainText(), selectedText() may include special unicode characters such as QChar::ParagraphSeparator.

See also QTextDocumentFragment::toPlainText().

source

pub unsafe fn selection_end(&self) -> c_int

Returns the end of the selection or position() if the cursor doesn't have a selection.

Calls C++ function: int QTextCursor::selectionEnd() const.

C++ documentation:

Returns the end of the selection or position() if the cursor doesn’t have a selection.

See also selectionStart(), position(), and anchor().

source

pub unsafe fn selection_start(&self) -> c_int

Returns the start of the selection or position() if the cursor doesn't have a selection.

Calls C++ function: int QTextCursor::selectionStart() const.

C++ documentation:

Returns the start of the selection or position() if the cursor doesn’t have a selection.

See also selectionEnd(), position(), and anchor().

source

pub unsafe fn set_block_char_format( &self, format: impl CastInto<Ref<QTextCharFormat>> )

Sets the block char format of the current block (or all blocks that are contained in the selection) to format.

Calls C++ function: void QTextCursor::setBlockCharFormat(const QTextCharFormat& format).

C++ documentation:

Sets the block char format of the current block (or all blocks that are contained in the selection) to format.

See also blockCharFormat().

source

pub unsafe fn set_block_format( &self, format: impl CastInto<Ref<QTextBlockFormat>> )

Sets the block format of the current block (or all blocks that are contained in the selection) to format.

Calls C++ function: void QTextCursor::setBlockFormat(const QTextBlockFormat& format).

C++ documentation:

Sets the block format of the current block (or all blocks that are contained in the selection) to format.

See also blockFormat() and mergeBlockFormat().

source

pub unsafe fn set_char_format( &self, format: impl CastInto<Ref<QTextCharFormat>> )

Sets the cursor's current character format to the given format. If the cursor has a selection, the given format is applied to the current selection.

Calls C++ function: void QTextCursor::setCharFormat(const QTextCharFormat& format).

C++ documentation:

Sets the cursor’s current character format to the given format. If the cursor has a selection, the given format is applied to the current selection.

See also charFormat(), hasSelection(), and mergeCharFormat().

source

pub unsafe fn set_keep_position_on_insert(&self, b: bool)

Defines whether the cursor should keep its current position when text gets inserted at the current position of the cursor.

Calls C++ function: void QTextCursor::setKeepPositionOnInsert(bool b).

C++ documentation:

Defines whether the cursor should keep its current position when text gets inserted at the current position of the cursor.

If b is true, the cursor keeps its current position when text gets inserted at the positing of the cursor. If b is false, the cursor moves along with the inserted text.

The default is false.

Note that a cursor always moves when text is inserted before the current position of the cursor, and it always keeps its position when text is inserted after the current position of the cursor.

This function was introduced in Qt 4.7.

See also keepPositionOnInsert().

source

pub unsafe fn set_position_2a(&self, pos: c_int, mode: MoveMode)

Moves the cursor to the absolute position in the document specified by pos using a MoveMode specified by m. The cursor is positioned between characters.

Calls C++ function: void QTextCursor::setPosition(int pos, QTextCursor::MoveMode mode = …).

C++ documentation:

Moves the cursor to the absolute position in the document specified by pos using a MoveMode specified by m. The cursor is positioned between characters.

See also position(), movePosition(), and anchor().

source

pub unsafe fn set_position_1a(&self, pos: c_int)

Moves the cursor to the absolute position in the document specified by pos using a MoveMode specified by m. The cursor is positioned between characters.

Calls C++ function: void QTextCursor::setPosition(int pos).

C++ documentation:

Moves the cursor to the absolute position in the document specified by pos using a MoveMode specified by m. The cursor is positioned between characters.

See also position(), movePosition(), and anchor().

source

pub unsafe fn set_vertical_movement_x(&self, x: c_int)

Sets the visual x position for vertical cursor movements to x.

Calls C++ function: void QTextCursor::setVerticalMovementX(int x).

C++ documentation:

Sets the visual x position for vertical cursor movements to x.

The vertical movement x position is cleared automatically when the cursor moves horizontally, and kept unchanged when the cursor moves vertically. The mechanism allows the cursor to move up and down on a visually straight line with proportional fonts, and to gently "jump" over short lines.

A value of -1 indicates no predefined x position. It will then be set automatically the next time the cursor moves up or down.

This function was introduced in Qt 4.7.

See also verticalMovementX().

source

pub unsafe fn set_visual_navigation(&self, b: bool)

Sets visual navigation to b.

Calls C++ function: void QTextCursor::setVisualNavigation(bool b).

C++ documentation:

Sets visual navigation to b.

Visual navigation means skipping over hidden text paragraphs. The default is false.

This function was introduced in Qt 4.4.

See also visualNavigation() and movePosition().

source

pub unsafe fn swap(&self, other: impl CastInto<Ref<QTextCursor>>)

Swaps this text cursor instance with other. This function is very fast and never fails.

Calls C++ function: void QTextCursor::swap(QTextCursor& other).

C++ documentation:

Swaps this text cursor instance with other. This function is very fast and never fails.

This function was introduced in Qt 5.0.

source

pub unsafe fn vertical_movement_x(&self) -> c_int

Returns the visual x position for vertical cursor movements.

Calls C++ function: int QTextCursor::verticalMovementX() const.

C++ documentation:

Returns the visual x position for vertical cursor movements.

A value of -1 indicates no predefined x position. It will then be set automatically the next time the cursor moves up or down.

This function was introduced in Qt 4.7.

See also setVerticalMovementX().

source

pub unsafe fn visual_navigation(&self) -> bool

Returns true if the cursor does visual navigation; otherwise returns false.

Calls C++ function: bool QTextCursor::visualNavigation() const.

C++ documentation:

Returns true if the cursor does visual navigation; otherwise returns false.

Visual navigation means skipping over hidden text paragraphs. The default is false.

This function was introduced in Qt 4.4.

See also setVisualNavigation() and movePosition().

Trait Implementations§

source§

impl CppDeletable for QTextCursor

source§

unsafe fn delete(&self)

Destroys the QTextCursor.

Calls C++ function: [destructor] void QTextCursor::~QTextCursor().

C++ documentation:

Destroys the QTextCursor.

source§

impl Ge<Ref<QTextCursor>> for QTextCursor

source§

unsafe fn ge(&self, rhs: &Ref<QTextCursor>) -> bool

Returns true if the other cursor is positioned earlier or at the same position in the document as this cursor; otherwise returns false.

Calls C++ function: bool QTextCursor::operator>=(const QTextCursor& rhs) const.

C++ documentation:

Returns true if the other cursor is positioned earlier or at the same position in the document as this cursor; otherwise returns false.

source§

impl Gt<Ref<QTextCursor>> for QTextCursor

source§

unsafe fn gt(&self, rhs: &Ref<QTextCursor>) -> bool

Returns true if the other cursor is positioned earlier in the document than this cursor; otherwise returns false.

Calls C++ function: bool QTextCursor::operator>(const QTextCursor& rhs) const.

C++ documentation:

Returns true if the other cursor is positioned earlier in the document than this cursor; otherwise returns false.

source§

impl Le<Ref<QTextCursor>> for QTextCursor

source§

unsafe fn le(&self, rhs: &Ref<QTextCursor>) -> bool

Returns true if the other cursor is positioned later or at the same position in the document as this cursor; otherwise returns false.

Calls C++ function: bool QTextCursor::operator<=(const QTextCursor& rhs) const.

C++ documentation:

Returns true if the other cursor is positioned later or at the same position in the document as this cursor; otherwise returns false.

source§

impl Lt<Ref<QTextCursor>> for QTextCursor

source§

unsafe fn lt(&self, rhs: &Ref<QTextCursor>) -> bool

Returns true if the other cursor is positioned later in the document than this cursor; otherwise returns false.

Calls C++ function: bool QTextCursor::operator<(const QTextCursor& rhs) const.

C++ documentation:

Returns true if the other cursor is positioned later in the document than this cursor; otherwise returns false.

source§

impl PartialEq<Ref<QTextCursor>> for QTextCursor

source§

fn eq(&self, rhs: &Ref<QTextCursor>) -> bool

Returns true if the other cursor is at the same position in the document as this cursor; otherwise returns false.

Calls C++ function: bool QTextCursor::operator==(const QTextCursor& rhs) const.

C++ documentation:

Returns true if the other cursor is at the same position in the document as this cursor; otherwise returns false.

1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T, U> CastInto<U> for T
where U: CastFrom<T>,

source§

unsafe fn cast_into(self) -> U

Performs the conversion. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> StaticUpcast<T> for T

source§

unsafe fn static_upcast(ptr: Ptr<T>) -> Ptr<T>

Convert type of a const pointer. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.