继承者: QPyTextObject
PySide.QtGui.QTextObjectInterface class allows drawing of custom text objects in PySide.QtGui.QTextDocument s.
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 type with PySide.QtGui.QTextCharFormat . A PySide.QtGui.QTextObjectInterface must also be implemented for this type and be registered 采用 PySide.QtGui.QAbstractTextDocumentLayout of the document. When the object type is encountered while rendering a PySide.QtGui.QTextDocument , PySide.QtGui.QTextObjectInterface.intrinsicSize() and PySide.QtGui.QTextObjectInterface.drawObject() functions of the interface are called.
The following list explains the required steps of inserting a custom text object into a document:
A class implementing a text object needs to inherit both PySide.QtCore.QObject and PySide.QtGui.QTextObjectInterface . PySide.QtCore.QObject must be the first class inherited. For instance:
class SvgTextObject(QObject, QTextObjectInterface):
def __init__(self,...):
super(SvgTextObject, self).__init__(...)
...
The data of a text object is usually stored in the PySide.QtGui.QTextCharFormat 使用 QTextCharFormat.setProperty() , and then retrieved with QTextCharFormat.property() .
警告
拷贝和粘贴操作忽略自定义文本对象。
另请参阅
文本对象范例 PySide.QtGui.QTextCharFormat PySide.QtGui.QTextLayout
| 参数: |
|
|---|
绘制此文本对象使用指定 painter .
The size of the rectangle, rect , to draw in is the size previously calculated by PySide.QtGui.QTextObjectInterface.intrinsicSize() . The rectangles position is relative to the painter .
You also get the document ( doc ) and the position ( posInDocument ) of the format in that document.
| 参数: |
|
|---|---|
| 返回类型: |
PySide.QtGui.QTextObjectInterface.intrinsicSize() function returns the size of the text object represented by format in the given document ( doc ) at the given position ( posInDocument ).
The size calculated will be used for subsequent calls to PySide.QtGui.QTextObjectInterface.drawObject() for this format .