PythonQt.Qt.QTextLayout
QTextLayout
PythonQtInstanceWrapper object
Native bases: PythonQtInstanceWrapper
Supplemental documentation: Qt 5 reference:
Detailed Description
It offers many features expected from a modern text layout engine, including Unicode compliant rendering, line breaking and handling of cursor positioning. It can also produce and render device independent layout, something that is important for WYSIWYG applications.
The class has a rather low level API and unless you intend to implement your own text rendering for some specialized widget, you probably won't need to use it directly.
QTextLayout can be used with both plain and rich text.
QTextLayout can be used to create a sequence of QTextLine instances with given widths and can position them independently on the screen. Once the layout is done, these lines can be drawn on a paint device.
The text to be laid out can be provided in the constructor or set with setText().
The layout can be seen as a sequence of QTextLine objects; use createLine() to create a QTextLine instance, and lineAt() or lineForTextPosition() to retrieve created lines.
Here is a code snippet that demonstrates the layout phase:
int leading = fontMetrics.leading();
qreal height = 0;
textLayout.setCacheEnabled(true);
textLayout.beginLayout();
while (1) {
QTextLine line = textLayout.createLine();
if (!line.isValid())
break;
line.setLineWidth(lineWidth);
height += leading;
line.setPosition(QPointF(0, height));
height += line.height();
}
textLayout.endLayout();
The text can then be rendered by calling the layout's draw() function:
QPainter painter(this);
textLayout.draw(&painter, QPoint(0, 0));
For a given position in the text you can find a valid cursor position with isValidCursorPosition(), nextCursorPosition(), and previousCursorPosition().
The QTextLayout itself can be positioned with setPosition(); it has a boundingRect(), and a minimumWidth() and a maximumWidth().
Source: https://doc.qt.io/archives/qt-5.15/qtextlayout.html
Complete member index
Every captured member retains its own identity. Identical captured declaration text is linked once; this does not establish native inheritance or interchangeable objects.
| Member | Kind | Signature | Summary |
|---|---|---|---|
CursorMode |
attribute | type |
Convert a number or string to an integer, or return 0 if no arguments are given. (shared captured text) |
FormatRange |
attribute | type |
(shared captured text) |
SkipCharacters |
attribute | Any |
(shared captured text) |
SkipWords |
attribute | Any |
(shared captured text) |
__init__ |
function | (self, *args: Any, **kwargs: Any) -> None |
Native constructor; consult class documentation for supported overloads. (shared captured text) |
additionalFormats |
function | (self) -> tuple |
X.additionalFormats() -> tuple (shared captured text) |
beginLayout |
function | (self) -> None |
Begins the layout process. (shared captured text) |
boundingRect |
function | (self) -> Any |
X.boundingRect() -> PythonQt.QtCore.QRectF (shared captured text) |
cacheEnabled |
function | (self) -> bool |
X.cacheEnabled() -> bool (shared captured text) |
className |
function | (self, *args: Any, **kwargs: Any) -> Any |
Return the classname of the object (shared captured text) |
clearAdditionalFormats |
function | (self) -> None |
(shared captured text) |
clearFormats |
function | (self) -> None |
Clears the list of additional formats supported by the text layout. (shared captured text) |
clearLayout |
function | (self) -> None |
Clears the line information in the layout. (shared captured text) |
createLine |
function | (self) -> Any |
X.createLine() -> PythonQt.QtGui.QTextLine (shared captured text) |
cursorMoveStyle |
function | (self) -> Any |
The cursor movement style of this [QTextLayout](https://doc.qt.io/archives/qt-5.15/qtextlayout.html). (shared captured text) |
delete |
function | (self, *args: Any, **kwargs: Any) -> Any |
Deletes the C++ object (at your own risk, my friend!) (shared captured text) |
draw |
function | (self, p: Any, pos: Any, selections: Any, clip: Any) -> None |
X.draw(p, pos, selections, clip) (shared captured text) |
drawCursor |
function | (self, p: Any, pos: Any, cursorPosition: int, width: Any) -> None |
X.drawCursor(p, pos, cursorPosition, width) (shared captured text) |
endLayout |
function | (self) -> None |
Ends the layout process. (shared captured text) |
font |
function | (self) -> Any |
X.font() -> PythonQt.QtGui.QFont (shared captured text) |
formats |
function | (self) -> tuple |
X.formats() -> tuple (shared captured text) |
glyphRuns |
function | (self, *args: Any, **kwargs: Any) -> Any |
X.glyphRuns(from, length) -> tuple (shared captured text) |
help |
function | (self, *args: Any, **kwargs: Any) -> Any |
Shows the help of available methods for this class (shared captured text) |
inherits |
function | (self, *args: Any, **kwargs: Any) -> Any |
Returns if the class inherits or is of given type name (shared captured text) |
isValidCursorPosition |
function | (self, pos: int) -> bool |
X.isValidCursorPosition(pos) -> bool (shared captured text) |
leftCursorPosition |
function | (self, oldPos: int) -> int |
X.leftCursorPosition(oldPos) -> int (shared captured text) |
lineAt |
function | (self, i: int) -> Any |
X.lineAt(i) -> PythonQt.QtGui.QTextLine (shared captured text) |
lineCount |
function | (self) -> int |
X.lineCount() -> int (shared captured text) |
lineForTextPosition |
function | (self, pos: int) -> Any |
X.lineForTextPosition(pos) -> PythonQt.QtGui.QTextLine (shared captured text) |
maximumWidth |
function | (self) -> float |
X.maximumWidth() -> float (shared captured text) |
minimumWidth |
function | (self) -> float |
X.minimumWidth() -> float (shared captured text) |
nextCursorPosition |
function | (self, oldPos: int, mode: Any) -> int |
X.nextCursorPosition(oldPos, mode) -> int (shared captured text) |
position |
function | (self) -> Any |
X.position() -> PythonQt.QtCore.QPointF (shared captured text) |
preeditAreaPosition |
function | (self) -> int |
X.preeditAreaPosition() -> int (shared captured text) |
preeditAreaText |
function | (self) -> str |
X.preeditAreaText() -> str (shared captured text) |
previousCursorPosition |
function | (self, oldPos: int, mode: Any) -> int |
X.previousCursorPosition(oldPos, mode) -> int (shared captured text) |
rightCursorPosition |
function | (self, oldPos: int) -> int |
X.rightCursorPosition(oldPos) -> int (shared captured text) |
setAdditionalFormats |
function | (self, overrides: Any) -> None |
(shared captured text) |
setCacheEnabled |
function | (self, enable: bool) -> None |
Enables caching of the complete layout information if enable is true; otherwise disables layout caching. (shared captured text) |
setCursorMoveStyle |
function | (self, style: Any) -> None |
Sets the visual cursor movement style to the given style. (shared captured text) |
setFlags |
function | (self, arg0: flags) -> None |
(shared captured text) |
setFont |
function | (self, f: Any) -> None |
Sets the layout's font to the given font. (shared captured text) |
setFormats |
function | (self, overrides: Any) -> None |
Sets the additional formats supported by the text layout to formats. (shared captured text) |
setPosition |
function | (self, p: Any) -> None |
Moves the text layout to point p. (shared captured text) |
setPreeditArea |
function | (self, position: int, text: str) -> None |
X.setPreeditArea(position, text) (shared captured text) |
setRawFont |
function | (self, rawFont: Any) -> None |
(shared captured text) |
setText |
function | (self, string: str) -> None |
Sets the layout's text to the given string. (shared captured text) |
setTextOption |
function | (self, option: Any) -> None |
Sets the text option structure that controls the layout process to the given option. (shared captured text) |
text |
function | (self) -> str |
X.text() -> str (shared captured text) |
textOption |
function | (self) -> Any |
X.textOption() -> PythonQt.QtGui.QTextOption (shared captured text) |