PySide6.QtGui.QTextObjectInterface¶
- class QTextObjectInterface¶
- The - QTextObjectInterfaceclass allows drawing of custom text objects in- QTextDocuments. More…- Synopsis¶- Virtual methods¶- def - drawObject()
- def - intrinsicSize()
 - 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¶- Warning - This section contains snippets that were automatically translated from C++ to Python and may contain errors. - A text object describes the structure of one or more elements in a text document; for instance, images imported from HTML are implemented using text objects. A text object knows how to lay out and draw its elements when a document is being rendered. - Qt allows custom text objects to be inserted into a document by registering a custom - object typewith- QTextCharFormat. A- QTextObjectInterfacemust also be implemented for this type and be- registeredwith the- QAbstractTextDocumentLayoutof the document. When the object type is encountered while rendering a- QTextDocument, the- intrinsicSize()and- drawObject()functions of the interface are called.- The following list explains the required steps of inserting a custom text object into a document: - Choose an - objectType. The- objectTypeis an integer with a value greater or equal to- UserObject.
- Create a - QTextCharFormatobject and set the object type to the chosen type using the setObjectType() function.
- Implement the - QTextObjectInterfaceclass.
- Call - registerHandler()with an instance of your- QTextObjectInterfacesubclass to register your object type.
- Insert QChar::ObjectReplacementCharacter with the aforementioned - QTextCharFormatof the chosen object type into the document. As mentioned, the functions of- QTextObjectInterface- intrinsicSize()and- drawObject()will then be called with the- QTextFormatas parameter whenever the replacement character is encountered.
 - A class implementing a text object needs to inherit both QObject and - QTextObjectInterface. QObject must be the first class inherited. For instance:- class SvgTextObject(QObject, QTextObjectInterface): Q_OBJECT Q_INTERFACES(QTextObjectInterface) - The data of a text object is usually stored in the - QTextCharFormatusing- setProperty(), and then retrieved with- property().- abstract drawObject(painter, rect, doc, posInDocument, format)¶
- Parameters:
- painter – - QPainter
- rect – - QRectF
- doc – - QTextDocument
- posInDocument – int 
- format – - QTextFormat
 
 
 - Draws this text object using the specified - painter.- The size of the rectangle, - rect, to draw in is the size previously calculated by- intrinsicSize(). The rectangles position is relative to the- painter.- You also get the document ( - doc) and the position (- posInDocument) of the- formatin that document.- See also - abstract intrinsicSize(doc, posInDocument, format)¶
- Parameters:
- doc – - QTextDocument
- posInDocument – int 
- format – - QTextFormat
 
- Return type:
 
 - The intrinsicSize() function returns the size of the text object represented by - formatin the given document (- doc) at the given position (- posInDocument).- The size calculated will be used for subsequent calls to - drawObject()for this- format.- See also