Movatterモバイル変換


[0]ホーム

URL:


We bake cookies in your browser for a better experience. Using this site means that you consent.Read More

Menu

Qt Documentation

QTextCursor Class

TheQTextCursor class offers an API to access and modify QTextDocuments.More...

Header:#include <QTextCursor>

Note: All functions in this class arereentrant.

Public Types

enumMoveMode { MoveAnchor, KeepAnchor }
enumMoveOperation { NoMove, Start, StartOfLine, StartOfBlock, ..., PreviousRow }
enumSelectionType { Document, BlockUnderCursor, LineUnderCursor, WordUnderCursor }

Public Functions

QTextCursor()
QTextCursor(QTextDocument * document)
QTextCursor(QTextFrame * frame)
QTextCursor(const QTextBlock & block)
QTextCursor(const QTextCursor & cursor)
~QTextCursor()
intanchor() const
boolatBlockEnd() const
boolatBlockStart() const
boolatEnd() const
boolatStart() const
voidbeginEditBlock()
QTextBlockblock() const
QTextCharFormatblockCharFormat() const
QTextBlockFormatblockFormat() const
intblockNumber() const
QTextCharFormatcharFormat() const
voidclearSelection()
intcolumnNumber() const
QTextList *createList(const QTextListFormat & format)
QTextList *createList(QTextListFormat::Style style)
QTextFrame *currentFrame() const
QTextList *currentList() const
QTextTable *currentTable() const
voiddeleteChar()
voiddeletePreviousChar()
QTextDocument *document() const
voidendEditBlock()
boolhasComplexSelection() const
boolhasSelection() const
voidinsertBlock()
voidinsertBlock(const QTextBlockFormat & format)
voidinsertBlock(const QTextBlockFormat & format, const QTextCharFormat & charFormat)
voidinsertFragment(const QTextDocumentFragment & fragment)
QTextFrame *insertFrame(const QTextFrameFormat & format)
voidinsertHtml(const QString & html)
voidinsertImage(const QTextImageFormat & format)
voidinsertImage(const QTextImageFormat & format, QTextFrameFormat::Position alignment)
voidinsertImage(const QString & name)
voidinsertImage(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)
voidinsertText(const QString & text)
voidinsertText(const QString & text, const QTextCharFormat & format)
boolisCopyOf(const QTextCursor & other) const
boolisNull() const
voidjoinPreviousEditBlock()
boolkeepPositionOnInsert() const
voidmergeBlockCharFormat(const QTextCharFormat & modifier)
voidmergeBlockFormat(const QTextBlockFormat & modifier)
voidmergeCharFormat(const QTextCharFormat & modifier)
boolmovePosition(MoveOperation operation, MoveMode mode = MoveAnchor, int n = 1)
intposition() const
intpositionInBlock() const
voidremoveSelectedText()
voidselect(SelectionType selection)
voidselectedTableCells(int * firstRow, int * numRows, int * firstColumn, int * numColumns) const
QStringselectedText() const
QTextDocumentFragmentselection() const
intselectionEnd() const
intselectionStart() const
voidsetBlockCharFormat(const QTextCharFormat & format)
voidsetBlockFormat(const QTextBlockFormat & format)
voidsetCharFormat(const QTextCharFormat & format)
voidsetKeepPositionOnInsert(bool b)
voidsetPosition(int pos, MoveMode m = MoveAnchor)
voidsetVerticalMovementX(int x)
voidsetVisualNavigation(bool b)
intverticalMovementX() const
boolvisualNavigation() const
booloperator!=(const QTextCursor & other) const
booloperator<(const QTextCursor & other) const
booloperator<=(const QTextCursor & other) const
QTextCursor &operator=(const QTextCursor & cursor)
booloperator==(const QTextCursor & other) const
booloperator>(const QTextCursor & other) const
booloperator>=(const QTextCursor & other) const

Detailed Description

TheQTextCursor 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 aQTextDocument 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 currentposition() then is always eitherbetween two consecutive characters in the string, or elsebefore the very first character orafter 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 immediatelybefore the cursorposition() in the document. Similarly, the "current block" is the block that contains the cursorposition().

AQTextCursor also has ananchor() position. The text that is between theanchor() and theposition() is the selection. Ifanchor() ==position() there is no selection.

The cursor position can be changed programmatically usingsetPosition() andmovePosition(); the latter can also be used to select text. For selections seeselectionStart(),selectionEnd(),hasSelection(),clearSelection(), andremoveSelectedText().

If theposition() is at the start of a blockatBlockStart() returns true; and if it is at the end of a blockatBlockEnd() returns true. The format of the current character is returned bycharFormat(), and the format of the current block is returned byblockFormat().

Formatting can be applied to the current text document using thesetCharFormat(),mergeCharFormat(),setBlockFormat() andmergeBlockFormat() 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 parts 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 usingcreateList().

Deletions can be achieved usingdeleteChar(),deletePreviousChar(), andremoveSelectedText().

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

Existing fragments of text can be inserted withinsertFragment() but, if you want to insert pieces of text in various formats, it is usually still easier to useinsertText() 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 withinsertList().
  • Tables are inserted with theinsertTable() 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 withinsertImage(). The image to be used can be specified in an image format, or by name.
  • Frames are inserted by callinginsertFrame() with a specified format.

Actions can be grouped (i.e. treated as a single action for undo/redo) usingbeginEditBlock() andendEditBlock().

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 asmovePosition() anddeleteChar() limit cursor movement to these valid positions.

See alsoRich Text Processing.

Member Type Documentation

enum QTextCursor::MoveMode

ConstantValueDescription
QTextCursor::MoveAnchor0Moves the anchor to the same position as the cursor itself.
QTextCursor::KeepAnchor1Keeps the anchor where it is.

If theanchor() is kept where it is and theposition() is moved, the text in between will be selected.

enum QTextCursor::MoveOperation

ConstantValueDescription
QTextCursor::NoMove0Keep the cursor where it is
QTextCursor::Start1Move to the start of the document.
QTextCursor::StartOfLine3Move to the start of the current line.
QTextCursor::StartOfBlock4Move to the start of the current block.
QTextCursor::StartOfWord5Move to the start of the current word.
QTextCursor::PreviousBlock6Move to the start of the previous block.
QTextCursor::PreviousCharacter7Move to the previous character.
QTextCursor::PreviousWord8Move to the beginning of the previous word.
QTextCursor::Up2Move up one line.
QTextCursor::Left9Move left one character.
QTextCursor::WordLeft10Move left one word.
QTextCursor::End11Move to the end of the document.
QTextCursor::EndOfLine13Move to the end of the current line.
QTextCursor::EndOfWord14Move to the end of the current word.
QTextCursor::EndOfBlock15Move to the end of the current block.
QTextCursor::NextBlock16Move to the beginning of the next block.
QTextCursor::NextCharacter17Move to the next character.
QTextCursor::NextWord18Move to the next word.
QTextCursor::Down12Move down one line.
QTextCursor::Right19Move right one character.
QTextCursor::WordRight20Move right one word.
QTextCursor::NextCell21Move 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.
QTextCursor::PreviousCell22Move 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.
QTextCursor::NextRow23Move to the first new cell of the next row in the current table.
QTextCursor::PreviousRow24Move to the last cell of the previous row in the current table.

See alsomovePosition().

enum QTextCursor::SelectionType

This enum describes the types of selection that can be applied with theselect() function.

ConstantValueDescription
QTextCursor::Document3Selects the entire document.
QTextCursor::BlockUnderCursor2Selects the block of text under the cursor.
QTextCursor::LineUnderCursor1Selects the line of text under the cursor.
QTextCursor::WordUnderCursor0Selects the word under the cursor. If the cursor is not positioned within a string of selectable characters, no text is selected.

Member Function Documentation

QTextCursor::QTextCursor()

Constructs a null cursor.

QTextCursor::QTextCursor(QTextDocument * document)

Constructs a cursor pointing to the beginning of thedocument.

QTextCursor::QTextCursor(QTextFrame * frame)

Constructs a cursor pointing to the beginning of theframe.

QTextCursor::QTextCursor(constQTextBlock & block)

Constructs a cursor pointing to the beginning of theblock.

QTextCursor::QTextCursor(constQTextCursor & cursor)

Constructs a new cursor that is a copy ofcursor.

QTextCursor::~QTextCursor()

Destroys theQTextCursor.

int QTextCursor::anchor() const

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

See alsoposition(),setPosition(),movePosition(),selectionStart(), andselectionEnd().

bool QTextCursor::atBlockEnd() const

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

See alsoatBlockStart() andatEnd().

bool QTextCursor::atBlockStart() const

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

See alsoatBlockEnd() andatStart().

bool QTextCursor::atEnd() const

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

This function was introduced in Qt 4.6.

See alsoatStart() andatBlockEnd().

bool QTextCursor::atStart() const

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

See alsoatBlockStart() andatEnd().

void QTextCursor::beginEditBlock()

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 andendEditBlock. The top-most pair will determine the scope of the undo/redo operation.

See alsoendEditBlock().

QTextBlock QTextCursor::block() const

Returns the block that contains the cursor.

QTextCharFormat QTextCursor::blockCharFormat() const

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 alsosetBlockCharFormat().

QTextBlockFormat QTextCursor::blockFormat() const

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

See alsosetBlockFormat() andcharFormat().

int QTextCursor::blockNumber() const

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.

QTextCharFormat QTextCursor::charFormat() const

Returns the format of the character immediately before the cursorposition(). 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 alsosetCharFormat(),insertText(), andblockFormat().

void QTextCursor::clearSelection()

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

Note that it doesnot delete the text of the selection.

See alsoremoveSelectedText() andhasSelection().

int QTextCursor::columnNumber() const

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 callpositionInBlock() instead.

This function was introduced in Qt 4.2.

See alsopositionInBlock().

QTextList * QTextCursor::createList(constQTextListFormat & format)

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

See alsoinsertList() andcurrentList().

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

This is an overloaded function.

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

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

See alsoinsertList() andcurrentList().

QTextFrame * QTextCursor::currentFrame() const

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

See alsoinsertFrame().

QTextList * QTextCursor::currentList() const

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

See alsoinsertList() andcreateList().

QTextTable * QTextCursor::currentTable() const

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

See alsoinsertTable().

void QTextCursor::deleteChar()

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

See alsodeletePreviousChar(),hasSelection(), andclearSelection().

void QTextCursor::deletePreviousChar()

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

See alsodeleteChar(),hasSelection(), andclearSelection().

QTextDocument * QTextCursor::document() const

Returns the document this cursor is associated with.

This function was introduced in Qt 4.5.

void QTextCursor::endEditBlock()

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 alsobeginEditBlock().

bool QTextCursor::hasComplexSelection() const

Returns true if the cursor contains a selection that is not simply a range fromselectionStart() toselectionEnd(); otherwise returns false.

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

bool QTextCursor::hasSelection() const

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

void QTextCursor::insertBlock()

Inserts a new empty block at the cursorposition() with the currentblockFormat() andcharFormat().

See alsosetBlockFormat().

void QTextCursor::insertBlock(constQTextBlockFormat & format)

This is an overloaded function.

Inserts a new empty block at the cursorposition() with block formatformat and the currentcharFormat() as block char format.

See alsosetBlockFormat().

void QTextCursor::insertBlock(constQTextBlockFormat & format, constQTextCharFormat & charFormat)

This is an overloaded function.

Inserts a new empty block at the cursorposition() with block formatformat andcharFormat as block char format.

See alsosetBlockFormat().

void QTextCursor::insertFragment(constQTextDocumentFragment & fragment)

Inserts the textfragment at the currentposition().

QTextFrame * QTextCursor::insertFrame(constQTextFrameFormat & format)

Inserts a frame with the givenformat at the current cursorposition(), moves the cursorposition() inside the frame, and returns the frame.

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

See alsohasSelection().

void QTextCursor::insertHtml(constQString & html)

Inserts the texthtml at the currentposition(). 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, useQTextDocument::setDefaultStyleSheet() instead.

This function was introduced in Qt 4.2.

void QTextCursor::insertImage(constQTextImageFormat & format)

Inserts the image defined byformat at the currentposition().

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

This is an overloaded function.

Inserts the image defined by the givenformat at the cursor's current position with the specifiedalignment.

This function was introduced in Qt 4.2.

See alsoposition().

void QTextCursor::insertImage(constQString & name)

This is an overloaded function.

Convenience method for inserting the image with the givenname at the currentposition().

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

void QTextCursor::insertImage(constQImage & image, constQString & name = QString())

This is an overloaded function.

Convenience function for inserting the givenimage with an optionalname at the currentposition().

This function was introduced in Qt 4.5.

QTextList * QTextCursor::insertList(constQTextListFormat & format)

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

See alsocurrentList(),createList(), andinsertBlock().

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

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 givenstyle. Returns the created list.

See alsocurrentList(),createList(), andinsertBlock().

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

Creates a new table with the given number ofrows andcolumns in the specifiedformat, inserts it at the current cursorposition() 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 alsocurrentTable().

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

This is an overloaded function.

Creates a new table with the given number ofrows andcolumns, inserts it at the current cursorposition() 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 alsocurrentTable().

void QTextCursor::insertText(constQString & text)

Insertstext at the current position, using the current character format.

If there is a selection, the selection is deleted and replaced bytext, 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. fromposition() 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 toinsertBlock() calls.

See alsocharFormat() andhasSelection().

void QTextCursor::insertText(constQString & text, constQTextCharFormat & format)

This is an overloaded function.

Insertstext at the current position with the givenformat.

bool QTextCursor::isCopyOf(constQTextCursor & other) const

Returns true if this cursor andother 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 alsooperator=() andoperator==().

bool QTextCursor::isNull() const

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

void QTextCursor::joinPreviousEditBlock()

LikebeginEditBlock() indicates the start of a block of editing operations that should appear as a single operation for undo/redo. However unlikebeginEditBlock() it does not start a new block but reverses the previous call toendEditBlock() 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 alsobeginEditBlock() andendEditBlock().

bool QTextCursor::keepPositionOnInsert() const

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 alsosetKeepPositionOnInsert().

void QTextCursor::mergeBlockCharFormat(constQTextCharFormat & modifier)

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

See alsosetBlockCharFormat().

void QTextCursor::mergeBlockFormat(constQTextBlockFormat & modifier)

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

See alsosetBlockFormat() andblockFormat().

void QTextCursor::mergeCharFormat(constQTextCharFormat & modifier)

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

See alsohasSelection() andsetCharFormat().

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

Moves the cursor by performing the givenoperationn times, using the specifiedmode, 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).

Ifmode isKeepAnchor, 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 alsosetVisualNavigation().

int QTextCursor::position() const

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

See alsosetPosition(),movePosition(),anchor(), andpositionInBlock().

int QTextCursor::positionInBlock() const

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

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

This function was introduced in Qt 4.7.

See alsoposition().

void QTextCursor::removeSelectedText()

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

See alsohasSelection().

void QTextCursor::select(SelectionType selection)

Selects text in the document according to the givenselection.

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

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, andnumRows andnumColumns 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.

QString QTextCursor::selectedText() const

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) useselection() 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. UseQString::replace() to replace these characters with newlines.

QTextDocumentFragment QTextCursor::selection() const

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

Note:UnlikeQTextDocumentFragment::toPlainText(),selectedText() may include special unicode characters such asQChar::ParagraphSeparator.

See alsoQTextDocumentFragment::toPlainText().

int QTextCursor::selectionEnd() const

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

See alsoselectionStart(),position(), andanchor().

int QTextCursor::selectionStart() const

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

See alsoselectionEnd(),position(), andanchor().

void QTextCursor::setBlockCharFormat(constQTextCharFormat & format)

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

See alsoblockCharFormat().

void QTextCursor::setBlockFormat(constQTextBlockFormat & format)

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

See alsoblockFormat() andmergeBlockFormat().

void QTextCursor::setCharFormat(constQTextCharFormat & format)

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

See alsocharFormat(),hasSelection(), andmergeCharFormat().

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.

Ifb is true, the cursor keeps its current position when text gets inserted at the positing of the cursor. Ifb 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 alsokeepPositionOnInsert().

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

Moves the cursor to the absolute position in the document specified bypos using aMoveMode specified bym. The cursor is positioned between characters.

See alsoposition(),movePosition(), andanchor().

void QTextCursor::setVerticalMovementX(int x)

Sets the visual x position for vertical cursor movements tox.

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 alsoverticalMovementX().

void QTextCursor::setVisualNavigation(bool b)

Sets visual navigation tob.

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

This function was introduced in Qt 4.4.

See alsovisualNavigation() andmovePosition().

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.

This function was introduced in Qt 4.7.

See alsosetVerticalMovementX().

bool QTextCursor::visualNavigation() const

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

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

This function was introduced in Qt 4.4.

See alsosetVisualNavigation() andmovePosition().

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

Returns true if theother cursor is at a different position in the document as this cursor; otherwise returns false.

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

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

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

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

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

Makes a copy ofcursor and assigns it to thisQTextCursor. Note thatQTextCursor is animplicitly shared class.

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

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

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

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

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

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

© 2016 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 theGNU 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.


[8]ページ先頭

©2009-2025 Movatter.jp