PySide6.QtCore.QTextBoundaryFinder¶
- class QTextBoundaryFinder¶
The
QTextBoundaryFinderclass provides a way of finding Unicode text boundaries in a string.Details
QTextBoundaryFinderallows to find Unicode text boundaries in a string, accordingly to the Unicode text boundary specification (see Unicode Standard Annex #14 and Unicode Standard Annex #29 ).QTextBoundaryFindercan operate on aQStringin four possible modes depending on the value ofBoundaryType.Units of Unicode characters that make up what the user thinks of as a character or basic unit of the language are here called Grapheme clusters. The two unicode characters ‘A’ + diaeresis do for example form one grapheme cluster as the user thinks of them as one character, yet it is in this case represented by two unicode code points (see https://www.unicode.org/reports/tr29/#Grapheme_Cluster_Boundaries ).
Word boundaries are there to locate the start and end of what a language considers to be a word (see https://www.unicode.org/reports/tr29/#Word_Boundaries ).
Line break boundaries give possible places where a line break might happen and sentence boundaries will show the beginning and end of whole sentences (see https://www.unicode.org/reports/tr29/#Sentence_Boundaries and https://www.unicode.org/reports/tr14/ ).
The first position in a string is always a valid boundary and refers to the position before the first character. The last position at the length of the string is also valid and refers to the position after the last character.
Synopsis¶
Methods¶
def
__init__()def
isAtBoundary()def
isValid()def
position()def
setPosition()def
string()def
toEnd()def
toNextBoundary()def
toStart()def
type()
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
- class BoundaryType¶
Constant
Description
QTextBoundaryFinder.BoundaryType.Grapheme
Finds a grapheme which is the smallest boundary. It including letters, punctuation marks, numerals and more.
QTextBoundaryFinder.BoundaryType.Word
Finds a word.
QTextBoundaryFinder.BoundaryType.Line
Finds possible positions for breaking the text into multiple lines.
QTextBoundaryFinder.BoundaryType.Sentence
Finds sentence boundaries. These include periods, question marks etc.
- class BoundaryReason¶
Constant
Description
QTextBoundaryFinder.BoundaryReason.NotAtBoundary
(inherits
enum.Flag) The boundary finder is not at a boundary position.QTextBoundaryFinder.BoundaryReason.BreakOpportunity
The boundary finder is at a break opportunity position. Such a break opportunity might also be an item boundary (either StartOfItem, EndOfItem, or combination of both), a mandatory line break, or a soft hyphen.
QTextBoundaryFinder.BoundaryReason.StartOfItem
The boundary finder is at the start of a grapheme, a word, a sentence, or a line.
QTextBoundaryFinder.BoundaryReason.EndOfItem
The boundary finder is at the end of a grapheme, a word, a sentence, or a line.
QTextBoundaryFinder.BoundaryReason.MandatoryBreak
The boundary finder is at the end of line (can occur for a Line boundary type only).
QTextBoundaryFinder.BoundaryReason.SoftHyphen
The boundary finder is at the soft hyphen (can occur for a Line boundary type only).
- __init__()¶
Constructs an invalid
QTextBoundaryFinderobject.- __init__(other)
- Parameters:
other –
QTextBoundaryFinder
Copies the
QTextBoundaryFinderobject,other.- __init__(type, string)
- Parameters:
type –
BoundaryTypestring – str
Creates a
QTextBoundaryFinderobject oftypeoperating onstring.- __init__(type, str[, buffer=None[, bufferSize=0]])
- Parameters:
type –
BoundaryTypestr – str
buffer –
unsigned charbufferSize – int
Creates a
QTextBoundaryFinderobject oftypeoperating onstring.bufferis an optional working buffer of sizebufferSizeyou can pass to theQTextBoundaryFinder. If the buffer is large enough to hold the working data required (bufferSize >= length + 1), it will use this instead of allocating its own buffer.Warning
QTextBoundaryFinderdoes not create a copy ofstring. It is the application programmer’s responsibility to ensure the array is allocated for as long as theQTextBoundaryFinderobject stays alive. The same applies tobuffer.- boundaryReasons()¶
- Return type:
Combination of
BoundaryReason
Returns the reasons for the boundary finder to have chosen the current position as a boundary.
- isAtBoundary()¶
- Return type:
bool
Returns
trueif the object’sposition()is currently at a valid text boundary.- isValid()¶
- Return type:
bool
Returns
trueif the text boundary finder is valid; otherwise returnsfalse. A defaultQTextBoundaryFinderis invalid.- position()¶
- Return type:
int
Returns the current position of the
QTextBoundaryFinder.The range is from 0 (the beginning of the string) to the length of the string inclusive.
See also
- setPosition(position)¶
- Parameters:
position – int
Sets the current position of the
QTextBoundaryFindertoposition.If
positionis out of bounds, it will be bound to only valid positions. In this case, valid positions are from 0 to the length of the string inclusive.See also
- string()¶
- Return type:
str
Returns the string the
QTextBoundaryFinderobject operates on.- toEnd()¶
Moves the finder to the end of the string. This is equivalent to
setPosition(string.length()).See also
- toNextBoundary()¶
- Return type:
int
Moves the
QTextBoundaryFinderto the next boundary position and returns that position.Returns -1 if there is no next boundary.
- toPreviousBoundary()¶
- Return type:
int
Moves the
QTextBoundaryFinderto the previous boundary position and returns that position.Returns -1 if there is no previous boundary.
- toStart()¶
Moves the finder to the start of the string. This is equivalent to
setPosition(0).See also
- type()¶
- Return type:
Returns the type of the
QTextBoundaryFinder.