PySide6.QtGui.QAbstractTextDocumentLayout¶
- class QAbstractTextDocumentLayout¶
- The - QAbstractTextDocumentLayoutclass is an abstract base class used to implement custom layouts for QTextDocuments. More_…- Inherited by: - QPlainTextDocumentLayout- Synopsis¶- Methods¶- def - __init__()
- def - anchorAt()
- def - document()
- def - format()
- def - formatAt()
- def - formatIndex()
- def - imageAt()
- def - paintDevice()
- def - setPaintDevice()
 - Virtual methods¶
- def - documentSize()
- def - draw()
- def - hitTest()
- def - pageCount()
 - Signals¶
- def - update()
- def - updateBlock()
 - 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 - QAbstractTextDocumentLayoutto provide custom layout behavior for your text documents.- An instance of the - QAbstractTextDocumentLayoutsubclass can be installed on a- QTextDocumentobject with the- setDocumentLayout()function.- You can insert custom objects into a - QTextDocument; see the- QTextObjectInterfaceclass description for details.- See also - __init__(doc)¶
- Parameters:
- doc – - QTextDocument
 
 - Creates a new text document layout for the given - document.- Returns the reference of the anchor the given - position, or an empty string if no anchor exists at that point.- abstract blockBoundingRect(block)¶
- Parameters:
- block – - QTextBlock
- Return type:
 
 - Returns the bounding rectangle of - block.- Returns the block (probably a list item) whose - markeris found at the given position- pos.- document()¶
- Return type:
 
 - Returns the text document that this layout is operating on. - abstract 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- charsAddedcorresponding 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, - charsRemovedwould be 0 and- charsAddedwould 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”, - charsRemovedwould be 5 and- charsAddedwould 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 corresponding- QTextLayoutobject needs to be processed. You can access the- QTextBlock‘s layout using the- layout()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 - 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 - This signal is emitted when the size of the document layout changes to - newSize.- Subclasses of - QAbstractTextDocumentLayoutshould 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 draw(painter, context)¶
- Parameters:
- painter – - QPainter
- context – - PaintContext
 
 
 - Draws the layout with the given - painterusing the given- context.- drawInlineObject(painter, rect, object, posInDocument, format)¶
- Parameters:
- painter – - QPainter
- rect – - QRectF
- object – - QTextInlineObject
- posInDocument – int 
- format – - QTextFormat
 
 
 - This function is called to draw the inline object, - object, with the given- painterwithin the rectangle specified by- rectusing the specified text- format.- posInDocumentspecifies 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 - format(pos)¶
- Parameters:
- pos – int 
- Return type:
 
 - Returns the character format that is applicable at the given - position.- Returns the text format at the given position - pos.- formatIndex(pos)¶
- Parameters:
- pos – int 
- Return type:
- int 
 
 - abstract frameBoundingRect(frame)¶
- Parameters:
- frame – - QTextFrame
- Return type:
 
 - Returns the bounding rectangle of - frame.- handlerForObject(objectType)¶
- Parameters:
- objectType – int 
- Return type:
 
 - Returns a handler for objects of the given - objectType.- abstract hitTest(point, accuracy)¶
- Parameters:
- point – - QPointF
- accuracy – - HitTestAccuracy
 
- Return type:
- int 
 
 - Returns the cursor position for the given - pointwith the specified- accuracy. Returns -1 if no valid cursor position was found.- Returns the source of the image at the given position - pos, or an empty string if no image exists at that point.- abstract pageCount()¶
- Return type:
- int 
 
 - Returns the number of pages contained in the layout. - See also - pageCountChanged(newPages)¶
- Parameters:
- newPages – int 
 
 - This signal is emitted when the number of pages in the layout changes; - newPagesis the updated page count.- Subclasses of - QAbstractTextDocumentLayoutshould 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 - paintDevice()¶
- Return type:
 
 - Returns the paint device used to render the document’s layout. - See also - positionInlineObject(item, posInDocument, format)¶
- Parameters:
- item – - QTextInlineObject
- posInDocument – int 
- format – - QTextFormat
 
 
 - Lays out the inline object - itemusing the given text- format.- posInDocumentspecifies 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 - Registers the given - componentas 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.- resizeInlineObject(item, posInDocument, format)¶
- Parameters:
- item – - QTextInlineObject
- posInDocument – int 
- format – - QTextFormat
 
 
 - Sets the size of the inline object - itemcorresponding to the text- format.- posInDocumentspecifies the position of the object within the document.- The default implementation resizes the - itemto 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(device)¶
- Parameters:
- device – - QPaintDevice
 
 - Sets the paint device used for rendering the document’s layout to the given - device.- See also - Unregisters the given - componentas a handler for items of the given- objectType, or any handler if the- componentis not specified.- This signal is emitted when the rectangle - recthas been updated.- Subclasses of - QAbstractTextDocumentLayoutshould emit this signal when the layout of the contents change in order to repaint.- updateBlock(block)¶
- Parameters:
- block – - QTextBlock
 
 - This signal is emitted when the specified - blockhas been updated.- Subclasses of - QAbstractTextDocumentLayoutshould emit this signal when the layout of- blockhas changed in order to repaint.- class Selection¶
- 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¶- PySide6.QtGui.QAbstractTextDocumentLayout.Selection.cursor¶
 - PySide6.QtGui.QAbstractTextDocumentLayout.Selection.format¶
 
 - class PaintContext¶
- Synopsis¶- Methods¶- def - __init__()
 - 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¶- PySide6.QtGui.QAbstractTextDocumentLayout.PaintContext.cursorPosition¶
 - PySide6.QtGui.QAbstractTextDocumentLayout.PaintContext.palette¶
 - PySide6.QtGui.QAbstractTextDocumentLayout.PaintContext.clip¶
 - PySide6.QtGui.QAbstractTextDocumentLayout.PaintContext.selections¶
 - __init__()¶