PySide6.QtGui.QTextFragment¶
- class QTextFragment¶
- The - QTextFragmentclass holds a piece of text in a- QTextDocumentwith a single- QTextCharFormat. More…- Synopsis¶- Methods¶- def - __init__()
- def - charFormat()
- def - contains()
- def - glyphRuns()
- def - isValid()
- def - length()
- def - __ne__()
- def - __lt__()
- def - __eq__()
- def - position()
- def - text()
 - Note - This documentation may contain snippets that were automatically translated from C++ to Python. We always welcome contributions to the snippet translation. If you see an issue with the translation, you can also let us know by creating a ticket on https:/bugreports.qt.io/projects/PYSIDE - Detailed Description¶- 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.- __init__()¶
 - Creates a new empty text fragment. - __init__(o)
- Parameters:
- o – - QTextFragment
 
 - Copies the content (text and format) of the - othertext fragment to this text fragment.- charFormat()¶
- Return type:
 
 - Returns the text fragment’s character format. - See also - charFormatIndex()¶
- Return type:
- int 
 
 - Returns an index into the document’s internal list of character formats for the text fragment’s character format. - See also - contains(position)¶
- Parameters:
- position – int 
- Return type:
- bool 
 
 - Returns - trueif the text fragment contains the text at the given- positionin the document; otherwise returns- false.- glyphRuns([from=-1[, length=-1]])¶
- Parameters:
- from – int 
- length – int 
 
- Return type:
- .list of QGlyphRun 
 
 - Returns the glyphs corresponding to - lencharacters of this text fragment starting at position- pos. The positions of the glyphs are relative to the position of the- QTextBlock‘s layout.- If - posis less than zero, it will default to the start of the- QTextFragment. If- lenis less than zero, it will default to the length of the fragment.- See also - isValid()¶
- Return type:
- bool 
 
 - Returns - trueif this is a valid text fragment (i.e. has a valid position in a document); otherwise returns- false.- length()¶
- Return type:
- int 
 
 - Returns the number of characters in the text fragment. - See also - __ne__(o)¶
- Parameters:
- o – - QTextFragment
- Return type:
- bool 
 
 - Returns - trueif this text fragment is different (at a different position) from the- othertext fragment; otherwise returns false.- __lt__(o)¶
- Parameters:
- o – - QTextFragment
- Return type:
- bool 
 
 - Returns - trueif this text fragment appears earlier in the document than the- othertext fragment; otherwise returns- false.- __eq__(o)¶
- Parameters:
- o – - QTextFragment
- Return type:
- bool 
 
 - Returns - trueif this text fragment is the same (at the same position) as the- othertext fragment; otherwise returns- false.- position()¶
- Return type:
- int 
 
 - Returns the position of this text fragment in the document. - text()¶
- Return type:
- str 
 
 - Returns the text fragment’s as plain text. - See also