Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
QTextFragment Class Reference

\reentrant More...

#include <qtextobject.h>

+ Collaboration diagram for QTextFragment:

Public Member Functions

 QTextFragment (const QTextDocumentPrivate *priv, int f, int fe)
 
 QTextFragment ()
 Creates a new empty text fragment.
 
 QTextFragment (const QTextFragment &o)
 Copies the content (text and format) of the other text fragment to this text fragment.
 
QTextFragmentoperator= (const QTextFragment &o)
 Assigns the content (text and format) of the other text fragment to this text fragment.
 
bool isValid () const
 Returns true if this is a valid text fragment (i.e.
 
bool operator== (const QTextFragment &o) const
 Returns true if this text fragment is the same (at the same position) as the other text fragment; otherwise returns false.
 
bool operator!= (const QTextFragment &o) const
 Returns true if this text fragment is different (at a different position) from the other text fragment; otherwise returns false.
 
bool operator< (const QTextFragment &o) const
 Returns true if this text fragment appears earlier in the document than the other text fragment; otherwise returns false.
 
int position () const
 Returns the position of this text fragment in the document.
 
int length () const
 Returns the number of characters in the text fragment.
 
bool contains (int position) const
 Returns true if the text fragment contains the text at the given position in the document; otherwise returns false.
 
QTextCharFormat charFormat () const
 Returns the text fragment's character format.
 
int charFormatIndex () const
 Returns an index into the document's internal list of character formats for the text fragment's character format.
 
QString text () const
 Returns the text fragment's as plain text.
 
QList< QGlyphRunglyphRuns (int from=-1, int length=-1) const
 Returns the glyphs corresponding to len characters of this text fragment starting at position pos.
 

Detailed Description

\reentrant

The QTextFragment class holds a piece of text in a QTextDocument with a single QTextCharFormat. \inmodule QtGui

A text fragment describes a piece of text that is stored with a single character format. Text in which the character format changes can be represented by sequences of text fragments with different formats.

If the user edits the text in a fragment and introduces a different character format, the fragment's text will be split at each point where the format changes, and new fragments will be created. For example, changing the style of some text in the middle of a sentence will cause the fragment to be broken into three separate fragments: the first and third with the same format as before, and the second with the new style. The first fragment will contain the text from the beginning of the sentence, the second will contain the text from the middle, and the third takes the text from the end of the sentence.

A fragment's text and character format can be obtained with the text() and charFormat() functions. The length() function gives the length of the text in the fragment. position() gives the position in the document of the start of the fragment. To determine whether the fragment contains a particular position within the document, use the contains() function.

See also
QTextDocument, {Rich Text Document Structure}

Definition at line 255 of file qtextobject.h.

Constructor & Destructor Documentation

◆ QTextFragment() [1/3]

QTextFragment::QTextFragment ( const QTextDocumentPrivate * priv,
int f,
int fe )
inline

Definition at line 258 of file qtextobject.h.

◆ QTextFragment() [2/3]

QTextFragment::QTextFragment ( )
inline

Creates a new empty text fragment.

Definition at line 259 of file qtextobject.h.

◆ QTextFragment() [3/3]

QTextFragment::QTextFragment ( const QTextFragment & o)
inline

Copies the content (text and format) of the other text fragment to this text fragment.

Definition at line 260 of file qtextobject.h.

Member Function Documentation

◆ charFormat()

QTextCharFormat QTextFragment::charFormat ( ) const

Returns the text fragment's character format.

See also
text()

Definition at line 1715 of file qtextobject.cpp.

Referenced by QWidgetTextControlPrivate::activateLinkUnderCursor(), QQuickTextControlPrivate::activateLinkUnderCursor(), QQuickTextNodeEngine::addTextBlock(), QWidgetTextControl::anchorPosition(), QWidgetTextControl::findNextPrevAnchor(), main(), and QTextOdfWriter::writeInlineCharacter().

+ Here is the caller graph for this function:

◆ charFormatIndex()

int QTextFragment::charFormatIndex ( ) const

Returns an index into the document's internal list of character formats for the text fragment's character format.

See also
QTextDocument::allFormats()

Definition at line 1729 of file qtextobject.cpp.

References QTextFragmentData::format.

◆ contains()

bool QTextFragment::contains ( int position) const

Returns true if the text fragment contains the text at the given position in the document; otherwise returns false.

Definition at line 1702 of file qtextobject.cpp.

References pos, and position().

Referenced by main().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ glyphRuns()

QList< QGlyphRun > QTextFragment::glyphRuns ( int pos = -1,
int len = -1 ) const

Returns the glyphs corresponding to len characters of this text fragment starting at position pos.

The positions of the glyphs are relative to the position of the QTextBlock's layout.

If pos is less than zero, it will default to the start of the QTextFragment. If len is less than zero, it will default to the length of the fragment.

See also
QGlyphRun, QTextBlock::layout(), QTextLayout::position(), QPainter::drawGlyphRun()

Definition at line 1640 of file qtextobject.cpp.

References QTextLine::glyphRuns(), i, layout, QLayout::layout(), pos, position(), and ret.

+ Here is the call graph for this function:

◆ isValid()

bool QTextFragment::isValid ( ) const
inline

Returns true if this is a valid text fragment (i.e.

has a valid position in a document); otherwise returns false.

Definition at line 263 of file qtextobject.h.

Referenced by main().

+ Here is the caller graph for this function:

◆ length()

int QTextFragment::length ( ) const

Returns the number of characters in the text fragment.

See also
text()

Definition at line 1684 of file qtextobject.cpp.

Referenced by QWidgetTextControlPrivate::activateLinkUnderCursor(), QQuickTextControlPrivate::activateLinkUnderCursor(), QQuickTextNodeEngine::addTextBlock(), QWidgetTextControl::findNextPrevAnchor(), and main().

+ Here is the caller graph for this function:

◆ operator!=()

bool QTextFragment::operator!= ( const QTextFragment & o) const
inline

Returns true if this text fragment is different (at a different position) from the other text fragment; otherwise returns false.

Definition at line 266 of file qtextobject.h.

References o.

◆ operator<()

bool QTextFragment::operator< ( const QTextFragment & o) const
inline

Returns true if this text fragment appears earlier in the document than the other text fragment; otherwise returns false.

Definition at line 267 of file qtextobject.h.

References o, and position().

+ Here is the call graph for this function:

◆ operator=()

QTextFragment & QTextFragment::operator= ( const QTextFragment & o)
inline

Assigns the content (text and format) of the other text fragment to this text fragment.

Definition at line 261 of file qtextobject.h.

References o.

◆ operator==()

bool QTextFragment::operator== ( const QTextFragment & o) const
inline

Returns true if this text fragment is the same (at the same position) as the other text fragment; otherwise returns false.

Definition at line 265 of file qtextobject.h.

References o.

◆ position()

int QTextFragment::position ( ) const

Returns the position of this text fragment in the document.

Definition at line 1671 of file qtextobject.cpp.

Referenced by QWidgetTextControlPrivate::activateLinkUnderCursor(), QQuickTextControlPrivate::activateLinkUnderCursor(), QWidgetTextControl::anchorPosition(), QWidgetTextControl::findNextPrevAnchor(), and main().

+ Here is the caller graph for this function:

◆ text()

QString QTextFragment::text ( ) const

Returns the text fragment's as plain text.

See also
length(), charFormat()

Definition at line 1742 of file qtextobject.cpp.

Referenced by QQuickTextNodeEngine::addTextBlock().

+ Here is the caller graph for this function:

The documentation for this class was generated from the following files: