QAbstractTextDocumentLayout#
The QAbstractTextDocumentLayout class is an abstract base class used to implement custom layouts for QTextDocuments. More…
Inherited by: QPlainTextDocumentLayout
Synopsis#
Functions#
- def - anchorAt(pos)
- def - blockWithMarkerAt(pos)
- def - document()
- def - format(pos)
- def - formatAt(pos)
- def - formatIndex(pos)
- def - handlerForObject(objectType)
- def - imageAt(pos)
- def - paintDevice()
- def - registerHandler(objectType, component)
- def - setPaintDevice(device)
- def - unregisterHandler(objectType[, component=None])
Virtual functions#
- def - blockBoundingRect(block)
- def - documentChanged(from, charsRemoved, charsAdded)
- def - documentSize()
- def - draw(painter, context)
- def - drawInlineObject(painter, rect, object, posInDocument, format)
- def - frameBoundingRect(frame)
- def - hitTest(point, accuracy)
- def - pageCount()
- def - positionInlineObject(item, posInDocument, format)
- def - resizeInlineObject(item, posInDocument, format)
Signals#
- def - documentSizeChanged(newSize)
- def - pageCountChanged(newPages)
- def - update([arg__1=QRectF(0., 0., 1000000000., 1000000000.)])
- def - updateBlock(block)
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#
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.
See also
- class PySide6.QtGui.QAbstractTextDocumentLayout(doc)#
- Parameters:
 
Creates a new text document layout for the given document.
- PySide6.QtGui.QAbstractTextDocumentLayout.anchorAt(pos)#
- Parameters:
- pos – - PySide6.QtCore.QPointF
- Return type:
- str 
 
Returns the reference of the anchor the given position, or an empty string if no anchor exists at that point.
- abstract PySide6.QtGui.QAbstractTextDocumentLayout.blockBoundingRect(block)#
- Parameters:
- block – - PySide6.QtGui.QTextBlock
- Return type:
 
Returns the bounding rectangle of block.
- PySide6.QtGui.QAbstractTextDocumentLayout.blockWithMarkerAt(pos)#
- Parameters:
- pos – - PySide6.QtCore.QPointF
- Return type:
 
Returns the block (probably a list item) whose marker is found at the given position pos.
- PySide6.QtGui.QAbstractTextDocumentLayout.document()#
- Return type:
 
Returns the text document that this layout is operating on.
- abstract PySide6.QtGui.QAbstractTextDocumentLayout.documentChanged(from, charsRemoved, charsAdded)#
- Parameters:
- from – int 
- charsRemoved – int 
- charsAdded – int 
 
 
This function is called whenever the contents of the document change. A change occurs when text is inserted, removed, or a combination of these two. The change is specified by position, charsRemoved, and charsAdded corresponding to the starting character position of the change, the number of characters removed from the document, and the number of characters added.
For example, when inserting the text “Hello” into an empty document, charsRemoved would be 0 and charsAdded would be 5 (the length of the string).
Replacing text is a combination of removing and inserting. For example, if the text “Hello” gets replaced by “Hi”, charsRemoved would be 5 and charsAdded would be 2.
For subclasses of QAbstractTextDocumentLayout , this is the central function where a large portion of the work to lay out and position document contents is done.
For example, in a subclass that only arranges blocks of text, an implementation of this function would have to do the following:
Determine the list of changed
QTextBlock(s) using the parameters provided.
Each
QTextBlockobject’s correspondingQTextLayoutobject needs to be processed. You can access theQTextBlock‘s layout using thelayout()function. This processing should take the document’s page size into consideration.
If the total number of pages changed, the
pageCountChanged()signal should be emitted.
If the total size changed, the
documentSizeChanged()signal should be emitted.
The
update()signal should be emitted to schedule a repaint of areas in the layout that require repainting.See also
- abstract PySide6.QtGui.QAbstractTextDocumentLayout.documentSize()#
- Return type:
 
Returns the total size of the document’s layout.
This information can be used by display widgets to update their scroll bars correctly.
See also
- PySide6.QtGui.QAbstractTextDocumentLayout.documentSizeChanged(newSize)#
- Parameters:
- newSize – - PySide6.QtCore.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
- abstract PySide6.QtGui.QAbstractTextDocumentLayout.draw(painter, context)#
- Parameters:
- painter – - PySide6.QtGui.QPainter
- context – - PySide6.QtGui.QAbstractTextDocumentLayout.PaintContext
 
 
Draws the layout with the given painter using the given context.
- PySide6.QtGui.QAbstractTextDocumentLayout.drawInlineObject(painter, rect, object, posInDocument, format)#
- Parameters:
- painter – - PySide6.QtGui.QPainter
- rect – - PySide6.QtCore.QRectF
- object – - PySide6.QtGui.QTextInlineObject
- posInDocument – int 
- format – - PySide6.QtGui.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
- PySide6.QtGui.QAbstractTextDocumentLayout.format(pos)#
- Parameters:
- pos – int 
- Return type:
 
Returns the character format that is applicable at the given position.
- PySide6.QtGui.QAbstractTextDocumentLayout.formatAt(pos)#
- Parameters:
- pos – - PySide6.QtCore.QPointF
- Return type:
 
Returns the text format at the given position pos.
- PySide6.QtGui.QAbstractTextDocumentLayout.formatIndex(pos)#
- Parameters:
- pos – int 
- Return type:
- int 
 
- abstract PySide6.QtGui.QAbstractTextDocumentLayout.frameBoundingRect(frame)#
- Parameters:
- frame – - PySide6.QtGui.QTextFrame
- Return type:
 
Returns the bounding rectangle of frame.
- PySide6.QtGui.QAbstractTextDocumentLayout.handlerForObject(objectType)#
- Parameters:
- objectType – int 
- Return type:
 
Returns a handler for objects of the given objectType.
- abstract PySide6.QtGui.QAbstractTextDocumentLayout.hitTest(point, accuracy)#
- Parameters:
- point – - PySide6.QtCore.QPointF
- accuracy – - HitTestAccuracy
 
- Return type:
- int 
 
Returns the cursor position for the given point with the specified accuracy. Returns -1 if no valid cursor position was found.
- PySide6.QtGui.QAbstractTextDocumentLayout.imageAt(pos)#
- Parameters:
- pos – - PySide6.QtCore.QPointF
- Return type:
- str 
 
Returns the source of the image at the given position pos, or an empty string if no image exists at that point.
- abstract PySide6.QtGui.QAbstractTextDocumentLayout.pageCount()#
- Return type:
- int 
 
Returns the number of pages contained in the layout.
See also
- PySide6.QtGui.QAbstractTextDocumentLayout.pageCountChanged(newPages)#
- Parameters:
- newPages – 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
- PySide6.QtGui.QAbstractTextDocumentLayout.paintDevice()#
- Return type:
 
Returns the paint device used to render the document’s layout.
See also
- PySide6.QtGui.QAbstractTextDocumentLayout.positionInlineObject(item, posInDocument, format)#
- Parameters:
- posInDocument – int 
- format – - PySide6.QtGui.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
- PySide6.QtGui.QAbstractTextDocumentLayout.registerHandler(objectType, component)#
- Parameters:
- objectType – int 
- component – - PySide6.QtCore.QObject
 
 
Registers the given component as a handler for items of the given objectType.
Note
registerHandler() 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.
- PySide6.QtGui.QAbstractTextDocumentLayout.resizeInlineObject(item, posInDocument, format)#
- Parameters:
- posInDocument – int 
- format – - PySide6.QtGui.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.
- PySide6.QtGui.QAbstractTextDocumentLayout.setPaintDevice(device)#
- Parameters:
- device – - PySide6.QtGui.QPaintDevice
 
Sets the paint device used for rendering the document’s layout to the given device.
See also
- PySide6.QtGui.QAbstractTextDocumentLayout.unregisterHandler(objectType[, component=None])#
- Parameters:
- objectType – int 
- component – - PySide6.QtCore.QObject
 
 
Unregisters the given component as a handler for items of the given objectType, or any handler if the component is not specified.
- PySide6.QtGui.QAbstractTextDocumentLayout.update([arg__1=QRectF(0., 0., 1000000000., 1000000000.)])#
- Parameters:
- arg__1 – - PySide6.QtCore.QRectF
 
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.
- PySide6.QtGui.QAbstractTextDocumentLayout.updateBlock(block)#
- Parameters:
- block – - PySide6.QtGui.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.