QAbstractTextDocumentLayout

PyQt6.QtGui.QAbstractTextDocumentLayout

Inherits from QObject.

Inherited by QPlainTextDocumentLayout.

Description

The QAbstractTextDocumentLayout class is an abstract base class used to implement custom layouts for QTextDocuments.

The standard layout provided by Qt can handle simple word processing including inline images, lists and tables.

Some applications, e.g., a word processor or a DTP application might need more features than the ones provided by Qt’s layout engine, in which case you can subclass QAbstractTextDocumentLayout to provide custom layout behavior for your text documents.

An instance of the QAbstractTextDocumentLayout subclass can be installed on a QTextDocument object with the setDocumentLayout() function.

You can insert custom objects into a QTextDocument; see the QTextObjectInterface class description for details.

Classes

PaintContext

Selection

Methods

__init__(QTextDocument)

Creates a new text document layout for the given document.


anchorAt(QPointF) str

Returns the reference of the anchor the given position, or an empty string if no anchor exists at that point.


blockBoundingRect(QTextBlock) QRectF

TODO


blockWithMarkerAt(QPointF) QTextBlock

Returns the block (probably a list item) whose marker() is found at the given position pos.


document() QTextDocument

Returns the text document that this layout is operating on.


documentChanged(int, int, int)

TODO


documentSize() QSizeF

TODO


draw(QPainter, PaintContext)

TODO


drawInlineObject(QPainter, QRectF, QTextInlineObject, int, QTextFormat)

This function is called to draw the inline object, object, with the given painter within the rectangle specified by rect using the specified text format.

posInDocument specifies the position of the object within the document.

The default implementation calls drawObject() on the object handlers. This function is called only within Qt. Subclasses can reimplement this function to customize the drawing of inline objects.

See also

draw().


format(int) QTextCharFormat

Returns the character format that is applicable at the given position.


formatAt(QPointF) QTextFormat

Returns the text format at the given position pos.


frameBoundingRect(QTextFrame) QRectF

TODO


handlerForObject(int) QTextObjectInterface

Returns a handler for objects of the given objectType.


hitTest(QPointF, HitTestAccuracy) int

TODO


imageAt(QPointF) str

Returns the source of the image at the given position pos, or an empty string if no image exists at that point.


pageCount() int

TODO


paintDevice() QPaintDevice

Returns the paint device used to render the document’s layout.

See also

setPaintDevice().


positionInlineObject(QTextInlineObject, int, QTextFormat)

Lays out the inline object item using the given text format.

posInDocument specifies the position of the object within the document.

The default implementation does nothing. This function is called only within Qt. Subclasses can reimplement this function to customize the position of inline objects.

See also

drawInlineObject().


registerHandler(int, QObject)

Registers the given component as a handler for items of the given objectType.

Note: has to be called once for each object type. This means that there is only one handler for multiple replacement characters of the same object type.

The text document layout does not take ownership of component.


resizeInlineObject(QTextInlineObject, int, QTextFormat)

Sets the size of the inline object item corresponding to the text format.

posInDocument specifies the position of the object within the document.

The default implementation resizes the item to the size returned by the object handler’s intrinsicSize() function. This function is called only within Qt. Subclasses can reimplement this function to customize the resizing of inline objects.


setPaintDevice(QPaintDevice)

Sets the paint device used for rendering the document’s layout to the given device.

See also

paintDevice().


unregisterHandler(int, component: QObject = None)

Unregisters the given component as a handler for items of the given objectType, or any handler if the component is not specified.

Signals

documentSizeChanged(QSizeF)

This signal is emitted when the size of the document layout changes to newSize.

Subclasses of QAbstractTextDocumentLayout should emit this signal when the document’s entire layout size changes. This signal is useful for widgets that display text documents since it enables them to update their scroll bars correctly.

See also

documentSize().


pageCountChanged(int)

This signal is emitted when the number of pages in the layout changes; newPages is the updated page count.

Subclasses of QAbstractTextDocumentLayout should emit this signal when the number of pages in the layout has changed. Changes to the page count are caused by changes to the layout or the document content itself.

See also

pageCount().


update(rect: QRectF = QRectF(0,0,1e+09,1e+09))

This signal is emitted when the rectangle rect has been updated.

Subclasses of QAbstractTextDocumentLayout should emit this signal when the layout of the contents change in order to repaint.


updateBlock(QTextBlock)

This signal is emitted when the specified block has been updated.

Subclasses of QAbstractTextDocumentLayout should emit this signal when the layout of block has changed in order to repaint.