QTextCursor 类

QTextCursor class offers an API to access and modify QTextDocuments. 更多...

头: #include <QTextCursor>
qmake: QT += gui

注意: 此类的所有函数 可重入 .

公共类型

enum MoveMode { MoveAnchor, KeepAnchor }
enum MoveOperation { NoMove, Start, StartOfLine, StartOfBlock, ..., PreviousRow }
enum SelectionType { Document, BlockUnderCursor, LineUnderCursor, WordUnderCursor }

公共函数

QTextCursor ()
QTextCursor (QTextDocument * document )
QTextCursor (QTextFrame * frame )
QTextCursor (const QTextBlock & block )
QTextCursor (const QTextCursor & cursor )
~QTextCursor ()
int anchor () const
bool atBlockEnd () const
bool atBlockStart () const
bool atEnd () const
bool atStart () const
void beginEditBlock ()
QTextBlock block () const
QTextCharFormat blockCharFormat () const
QTextBlockFormat blockFormat () const
int blockNumber () const
QTextCharFormat charFormat () const
void clearSelection ()
int columnNumber () const
QTextList * createList (const QTextListFormat & format )
QTextList * createList (QTextListFormat::Style style )
QTextFrame * currentFrame () const
QTextList * currentList () const
QTextTable * currentTable () const
void deleteChar ()
void deletePreviousChar ()
QTextDocument * document () const
void endEditBlock ()
bool hasComplexSelection () const
bool hasSelection () const
void insertBlock ()
void insertBlock (const QTextBlockFormat & format )
void insertBlock (const QTextBlockFormat & format , const QTextCharFormat & charFormat )
void insertFragment (const QTextDocumentFragment & fragment )
QTextFrame * insertFrame (const QTextFrameFormat & format )
void insertHtml (const QString & html )
void insertImage (const QTextImageFormat & format )
void insertImage (const QTextImageFormat & format , QTextFrameFormat::Position alignment )
void insertImage (const QString & name )
void insertImage (const QImage & image , const QString & name = QString())
QTextList * insertList (const QTextListFormat & format )
QTextList * insertList (QTextListFormat::Style style )
QTextTable * insertTable (int rows , int columns , const QTextTableFormat & format )
QTextTable * insertTable (int rows , int columns )
void insertText (const QString & text )
void insertText (const QString & text , const QTextCharFormat & format )
bool isCopyOf (const QTextCursor & other ) const
bool isNull () const
void joinPreviousEditBlock ()
bool keepPositionOnInsert () const
void mergeBlockCharFormat (const QTextCharFormat & modifier )
void mergeBlockFormat (const QTextBlockFormat & modifier )
void mergeCharFormat (const QTextCharFormat & modifier )
bool movePosition (MoveOperation operation , MoveMode mode = MoveAnchor, int n = 1)
int position () const
int positionInBlock () const
void removeSelectedText ()
void select (SelectionType selection )
void selectedTableCells (int * firstRow , int * numRows , int * firstColumn , int * numColumns ) const
QString selectedText () const
QTextDocumentFragment selection () const
int selectionEnd () const
int selectionStart () const
void setBlockCharFormat (const QTextCharFormat & format )
void setBlockFormat (const QTextBlockFormat & format )
void setCharFormat (const QTextCharFormat & format )
void setKeepPositionOnInsert (bool b )
void setPosition (int pos , MoveMode m = MoveAnchor)
void setVerticalMovementX (int x )
void setVisualNavigation (bool b )
void swap (QTextCursor & other )
int verticalMovementX () const
bool visualNavigation () const
bool operator!= (const QTextCursor & other ) const
bool operator< (const QTextCursor & other ) const
bool operator<= (const QTextCursor & other ) const
QTextCursor & operator= (QTextCursor && other )
QTextCursor & operator= (const QTextCursor & cursor )
bool operator== (const QTextCursor & other ) const
bool operator> (const QTextCursor & other ) const
bool operator>= (const QTextCursor & other ) const

详细描述

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 及它所做的任何选择。

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 () 则始终 between 字符串 2 连续字符,否则 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 () 位置。文本介于 anchor () 和 position () 是选定。若 anchor () == position (),没有选定。

可以按编程方式改变光标位置使用 setPosition () 和 movePosition ();后者还可用于选定文本。对于选定见 selectionStart (), selectionEnd (), hasSelection (), clearSelection (),和 removeSelectedText ().

position () 位于块开头, atBlockStart () 返回 true ;和若它位于块末尾, atBlockEnd () 返回 true。当前字符格式的返回通过 charFormat (),和当前块格式的返回通过 blockFormat ().

可以将格式化应用到当前文本文档使用 setCharFormat (), mergeCharFormat (), setBlockFormat () 和 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 ().

删除可以达成使用 deleteChar (), deletePreviousChar (),和 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 () 和 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 () 和 deleteChar () limit cursor movement to these valid positions.

另请参阅 富文本处理 .

成员类型文档编制

enum QTextCursor:: MoveMode

常量 描述
QTextCursor::MoveAnchor 0 将锚点移到如光标自身的相同位置。
QTextCursor::KeepAnchor 1 保持锚点位置。

anchor () 保持位置且 position () 被移动,会选中之间文本。

enum QTextCursor:: MoveOperation

常量 描述
QTextCursor::NoMove 0 保持光标位置
QTextCursor::Start 1 移至文档开头。
QTextCursor::StartOfLine 3 移至当前行开头。
QTextCursor::StartOfBlock 4 移至当前块开头。
QTextCursor::StartOfWord 5 移至当前单词开头。
QTextCursor::PreviousBlock 6 移至先前块开头。
QTextCursor::PreviousCharacter 7 移至上一字符。
QTextCursor::PreviousWord 8 移至先前单词开头。
QTextCursor::Up 2 上移一行。
QTextCursor::Left 9 左移一字符。
QTextCursor::WordLeft 10 左移一单词。
QTextCursor::End 11 移至文档末尾。
QTextCursor::EndOfLine 13 移至当前行末尾。
QTextCursor::EndOfWord 14 移至当前单词末尾。
QTextCursor::EndOfBlock 15 移至当前块末尾。
QTextCursor::NextBlock 16 移至下一块起始。
QTextCursor::NextCharacter 17 移至下一字符。
QTextCursor::NextWord 18 移至下一单词。
QTextCursor::Down 12 下移一行。
QTextCursor::Right 19 右移一字符。
QTextCursor::WordRight 20 右移一单词。
QTextCursor::NextCell 21 移到当前表格下一表格单元格的起始。若当前单元格是行的最后单元格,则光标移到下一行的第一单元格。
QTextCursor::PreviousCell 22 移到当前表格上一表格单元格的起始。若当前单元格是行的第一单元格,则光标将移到上一行的最后单元格。
QTextCursor::NextRow 23 移到当前表格下一行的第一新单元格。
QTextCursor::PreviousRow 24 移到当前表格上一行的最后单元格。

另请参阅 movePosition ().

enum QTextCursor:: SelectionType

此枚举描述的选定类型可应用于 select () 函数。

常量 描述
QTextCursor::Document 3 选择整个文档。
QTextCursor::BlockUnderCursor 2 选择光标下的文本块。
QTextCursor::LineUnderCursor 1 选择光标下的文本行。
QTextCursor::WordUnderCursor 0 选择光标下的单词。若光标不在可选字符的字符串内,则不选择文本。

成员函数文档编制

QTextCursor:: QTextCursor ()

构造 null 光标。

QTextCursor:: QTextCursor ( QTextDocument * document )

构造指向起始的光标为 document .

QTextCursor:: QTextCursor ( QTextFrame * frame )

构造指向起始的光标为 frame .

QTextCursor:: QTextCursor (const QTextBlock & block )

构造指向起始的光标为 block .

QTextCursor:: QTextCursor (const QTextCursor & cursor )

构造新副本光标为 cursor .

QTextCursor:: ~QTextCursor ()

销毁 QTextCursor .

int QTextCursor:: anchor () const

返回锚点位置;这如同 position () 除非存在选取,在这种情况下 position () 标记选择的一端而 anchor() 标记另一端。就像光标位置,锚点位置也在字符之间。

另请参阅 position (), setPosition (), movePosition (), selectionStart (),和 selectionEnd ().

bool QTextCursor:: atBlockEnd () const

返回 true 若光标在块末尾;否则返回 false .

另请参阅 atBlockStart () 和 atEnd ().

bool QTextCursor:: atBlockStart () const

返回 true 若光标在块开头;否则返回 false .

另请参阅 atBlockEnd () 和 atStart ().

bool QTextCursor:: atEnd () const

返回 true 若光标在文档末尾;否则返回 false .

该函数在 Qt 4.6 引入。

另请参阅 atStart () 和 atBlockEnd ().

bool QTextCursor:: atStart () const

返回 true 若光标在文档开头;否则返回 false .

另请参阅 atBlockStart () 和 atEnd ().

void QTextCursor:: beginEditBlock ()

开始在文档中编辑操作块的指示,这应该作为单一操作出现 (从撤销/重做角度来看)。

例如:

QTextCursor cursor(textDocument);
cursor.beginEditBlock();
cursor.insertText("Hello");
cursor.insertText("World");
cursor.endEditBlock();
textDocument->undo();
					

调用 undo() 将导致 2 插入被撤消,导致 World 和 Hello 两者被移除。

可以嵌套调用 beginEditBlock 和 endEditBlock 。最上面的一对将确定撤消/重做操作的作用域。

另请参阅 endEditBlock ().

QTextBlock QTextCursor:: block () const

返回包含光标的块。

QTextCharFormat QTextCursor:: blockCharFormat () const

返回光标所在块的块字符格式。

块字符格式是所用格式,当在空块开头插入文本时。

另请参阅 setBlockCharFormat ().

QTextBlockFormat QTextCursor:: blockFormat () const

返回光标所在块的块格式。

另请参阅 setBlockFormat () 和 charFormat ().

int QTextCursor:: blockNumber () const

返回光标所在块的编号,或 0 若光标无效。

注意:此函数在文档中才有意义,没有复杂对象 (譬如:表格或框架)。

该函数在 Qt 4.2 引入。

QTextCharFormat QTextCursor:: charFormat () const

立即返回光标之前的字符格式,在 position ()。若光标位于非空文本块的开头,则立即返回光标之后的字符格式。

另请参阅 setCharFormat (), insertText (),和 blockFormat ().

void QTextCursor:: clearSelection ()

清零当前选定,通过把锚点设置到光标位置。

Note that it does not 删除选定的文本。

另请参阅 removeSelectedText () 和 hasSelection ().

int QTextCursor:: columnNumber () const

返回在其包含行内的光标位置。

注意:这是相对于换行而不是相对于块 (即:段落) 的列号。

可能想要调用 positionInBlock () 代替。

该函数在 Qt 4.2 引入。

另请参阅 positionInBlock ().

QTextList *QTextCursor:: createList (const QTextListFormat & format )

创建并返回新列表采用给定 format ,并使当前段落光标位于第一列表项。

另请参阅 insertList () 和 currentList ().

QTextList *QTextCursor:: createList ( QTextListFormat::Style style )

这是重载函数。

创建并返回新列表采用给定 style ,使光标的当前段落成为第一列表项。

定义要使用样式通过 QTextListFormat::Style 枚举。

另请参阅 insertList () 和 currentList ().

QTextFrame *QTextCursor:: currentFrame () const

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

另请参阅 insertFrame ().

QTextList *QTextCursor:: currentList () const

返回当前列表若光标 position () is inside a block that is part of a list; otherwise returns 0.

另请参阅 insertList () 和 createList ().

QTextTable *QTextCursor:: currentTable () const

返回当前表格指针若光标 position () is inside a block that is part of a table; otherwise returns 0.

另请参阅 insertTable ().

void QTextCursor:: deleteChar ()

若没有选中文本,删除字符 at 当前光标位置;否则删除选中文本。

另请参阅 deletePreviousChar (), hasSelection (),和 clearSelection ().

void QTextCursor:: deletePreviousChar ()

若没有选中文本,删除字符 before 当前光标位置;否则删除选中文本。

另请参阅 deleteChar (), hasSelection (),和 clearSelection ().

QTextDocument *QTextCursor:: document () const

返回关联此光标的文档。

该函数在 Qt 4.5 引入。

void QTextCursor:: endEditBlock ()

指示应出现作为单操作的文档块编辑操作结束,从撤消/重做角度来看。

另请参阅 beginEditBlock ().

bool QTextCursor:: hasComplexSelection () const

返回 true 若光标包含的选定范围不只是从 selectionStart () 到 selectionEnd ();否则返回 false .

复杂选定是跨越表格至少 2 单元格的选择;其范围被指定通过 selectedTableCells ().

bool QTextCursor:: hasSelection () const

返回 true 光标包含选定;否则返回 false .

void QTextCursor:: insertBlock ()

插入新的空块在光标 position () 采用当前 blockFormat () 和 charFormat ().

另请参阅 setBlockFormat ().

void QTextCursor:: insertBlock (const QTextBlockFormat & format )

这是重载函数。

插入新的空块在光标 position () 采用块格式 format 和当前 charFormat () 作为块字符格式。

另请参阅 setBlockFormat ().

void QTextCursor:: insertBlock (const QTextBlockFormat & format , const QTextCharFormat & charFormat )

这是重载函数。

插入新的空块在光标 position () 采用块格式 format and charFormat 作为块字符格式。

另请参阅 setBlockFormat ().

void QTextCursor:: insertFragment (const QTextDocumentFragment & fragment )

插入文本 fragment 在当前 position ().

QTextFrame *QTextCursor:: insertFrame (const QTextFrameFormat & format )

插入框架采用给定 format 在当前光标 position (),移动光标 position () 在框架内,并返回框架。

若光标保有选定,整个选定被移入框架。

另请参阅 hasSelection ().

void QTextCursor:: insertHtml (const QString & html )

插入文本 html 在当前 position ()。文本被解释成 HTML。

注意: 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 () 代替。

该函数在 Qt 4.2 引入。

void QTextCursor:: insertImage (const QTextImageFormat & format )

插入图像定义通过 format 在当前 position ().

void QTextCursor:: insertImage (const QTextImageFormat & format , QTextFrameFormat::Position alignment )

这是重载函数。

插入图像定义通过给定 format 在光标的当前位置采用指定 alignment .

该函数在 Qt 4.2 引入。

另请参阅 position ().

void QTextCursor:: insertImage (const QString & name )

这是重载函数。

用于插入图像的方便方法采用给定 name 在当前 position ().

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

void QTextCursor:: insertImage (const QImage & image , const QString & name = QString())

这是重载函数。

方便函数用于插入给定 image 采用可选 name 在当前 position ().

该函数在 Qt 4.5 引入。

QTextList *QTextCursor:: insertList (const QTextListFormat & format )

Inserts a new block at the current position and makes it the first list item of a newly created list with the given format 。返回创建列表。

另请参阅 currentList (), createList (),和 insertBlock ().

QTextList *QTextCursor:: insertList ( QTextListFormat::Style style )

这是重载函数。

Inserts a new block at the current position and makes it the first list item of a newly created list with the given style 。返回创建列表。

另请参阅 currentList (), createList (),和 insertBlock ().

QTextTable *QTextCursor:: insertTable ( int rows , int columns , const QTextTableFormat & format )

创建新表采用给定数量的 rows and columns 以指定 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.

另请参阅 currentTable ().

QTextTable *QTextCursor:: insertTable ( int rows , int columns )

这是重载函数。

创建新表采用给定数量的 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.

另请参阅 currentTable ().

void QTextCursor:: insertText (const QString & text )

插入 text 在当前位置,使用当前字符格式。

若存在选定,选定被删除并替换通过 text ,例如:

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.

另请参阅 charFormat () 和 hasSelection ().

void QTextCursor:: insertText (const QString & text , const QTextCharFormat & format )

这是重载函数。

插入 text 在当前位置采用给定 format .

bool QTextCursor:: isCopyOf (const QTextCursor & other ) const

返回 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.

另请参阅 operator= () 和 operator== ().

bool QTextCursor:: isNull () const

返回 true 若光标为 null;否则返回 false 。null 光标被创建通过默认构造函数。

void QTextCursor:: joinPreviousEditBlock ()

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.

例如:

QTextCursor cursor(textDocument);
cursor.beginEditBlock();
cursor.insertText("Hello");
cursor.insertText("World");
cursor.endEditBlock();
...
cursor.joinPreviousEditBlock();
cursor.insertText("Hey");
cursor.endEditBlock();
textDocument->undo();
					

调用 undo() 将导致所有 3 插入被撤消。

另请参阅 beginEditBlock () 和 endEditBlock ().

bool QTextCursor:: keepPositionOnInsert () const

返回是否应该保持光标在当前位置,当将文本插入在光标位置处时。

默认为 false;

该函数在 Qt 4.7 引入。

另请参阅 setKeepPositionOnInsert ().

void QTextCursor:: mergeBlockCharFormat (const QTextCharFormat & modifier )

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 .

另请参阅 setBlockCharFormat ().

void QTextCursor:: mergeBlockFormat (const QTextBlockFormat & modifier )

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

另请参阅 setBlockFormat () 和 blockFormat ().

void QTextCursor:: mergeCharFormat (const QTextCharFormat & modifier )

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.

另请参阅 hasSelection () 和 setCharFormat ().

bool QTextCursor:: movePosition ( MoveOperation operation , MoveMode mode = MoveAnchor, int n = 1)

移动光标通过履行给定 operation n 次,使用指定 mode ,并返回 true 若所有操作均成功完成;否则返回 false .

例如:若重复使用此函数以寻址下一单词的末尾,它最终将失败,当到达文档末尾时。

默认情况下,移动操作被履行一次 ( n = 1).

mode is KeepAnchor ,光标选择由它移动覆盖的文本。这与用户达成的效果相同,当按下 Shift 键和采用光标键移动光标时。

另请参阅 setVisualNavigation ().

int QTextCursor:: position () const

返回光标在文档中的绝对位置。光标位于字符之间。

另请参阅 setPosition (), movePosition (), anchor (),和 positionInBlock ().

int QTextCursor:: positionInBlock () const

返回块内光标的相对位置。光标位于字符之间。

这相当于 position() - block().position() .

该函数在 Qt 4.7 引入。

另请参阅 position ().

void QTextCursor:: removeSelectedText ()

若存在选定,其内容被删除;否则什么都不做。

另请参阅 hasSelection ().

void QTextCursor:: select ( SelectionType selection )

选择文档文本,根据给定 selection .

void QTextCursor:: selectedTableCells ( int * firstRow , int * numRows , int * firstColumn , int * numColumns ) const

若选择跨越表格单元格, firstRow 是第一选定行的填充编号, firstColumn 是第一选定列的编号,而 numRows and numColumns 是选定行数和列数。若选定未跨越任何表格单元格,则结果是无害的但不确定。

QString QTextCursor:: selectedText () const

返回当前选定文本 (可能为空)。这仅返回文本,没有富文本格式化信息。若想要文档片段 (即:格式化的富文本),使用 selection () 代替。

注意: 若从编辑器获得的选定跨越换行符,文本将包含 Unicode U+2029 段落分隔符,而不是换行 \n 字符。使用 QString::replace () 以采用换行符替换这些字符。

QTextDocumentFragment QTextCursor:: selection () const

返回当前选定 (可能为空) 自带其所有格式信息。若仅仅希望选择文本 (即:纯文本),使用 selectedText () 代替。

注意: 不像 QTextDocumentFragment::toPlainText (), selectedText () 可能包括特殊 Unicode 字符,譬如 QChar::ParagraphSeparator .

另请参阅 QTextDocumentFragment::toPlainText ().

int QTextCursor:: selectionEnd () const

返回选定的结束,或 position () 若光标没有选定。

另请参阅 selectionStart (), position (),和 anchor ().

int QTextCursor:: selectionStart () const

返回选定的起始,或 position () 若光标没有选定。

另请参阅 selectionEnd (), position (),和 anchor ().

void QTextCursor:: setBlockCharFormat (const QTextCharFormat & format )

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

另请参阅 blockCharFormat ().

void QTextCursor:: setBlockFormat (const QTextBlockFormat & format )

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

另请参阅 blockFormat () 和 mergeBlockFormat ().

void QTextCursor:: setCharFormat (const QTextCharFormat & format )

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.

另请参阅 charFormat (), hasSelection (),和 mergeCharFormat ().

void QTextCursor:: setKeepPositionOnInsert ( bool b )

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

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.

默认为 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.

该函数在 Qt 4.7 引入。

另请参阅 keepPositionOnInsert ().

void QTextCursor:: setPosition ( int pos , MoveMode m = MoveAnchor)

移动光标到文档绝对位置,指定通过 pos 使用 MoveMode 指定通过 m . The cursor is positioned between characters.

另请参阅 position (), movePosition (),和 anchor ().

void QTextCursor:: setVerticalMovementX ( int x )

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.

该函数在 Qt 4.7 引入。

另请参阅 verticalMovementX ().

void QTextCursor:: setVisualNavigation ( bool b )

把视觉导航设为 b .

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

该函数在 Qt 4.4 引入。

另请参阅 visualNavigation () 和 movePosition ().

void QTextCursor:: swap ( QTextCursor & other )

交换此文本光标实例与 other 。此函数非常快,且从不失败。

该函数在 Qt 5.0 引入。

int QTextCursor:: verticalMovementX () const

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.

该函数在 Qt 4.7 引入。

另请参阅 setVerticalMovementX ().

bool QTextCursor:: visualNavigation () const

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

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

该函数在 Qt 4.4 引入。

另请参阅 setVisualNavigation () 和 movePosition ().

bool QTextCursor:: operator!= (const QTextCursor & other ) const

返回 true other cursor is at a different position in the document as this cursor; otherwise returns false .

bool QTextCursor:: operator< (const QTextCursor & other ) const

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

bool QTextCursor:: operator<= (const QTextCursor & other ) const

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

QTextCursor &QTextCursor:: operator= ( QTextCursor && other )

移动赋值运算符。

QTextCursor &QTextCursor:: operator= (const QTextCursor & cursor )

制作副本为 cursor 并将其赋值给此 QTextCursor 。注意, QTextCursor 隐式共享 类。

bool QTextCursor:: operator== (const QTextCursor & other ) const

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

bool QTextCursor:: operator> (const QTextCursor & other ) const

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

bool QTextCursor:: operator>= (const QTextCursor & other ) const

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