QTextObjectInterface Class Reference
[QtGui module]
该QTextObjectInterface类允许自定义文本对象的图形中QTextDocument秒。More…
通过继承QPyTextObject。
Methods
__init__ (self)
__init__ (self, QTextObjectInterface)
drawObject (self, QPainter painter, QRectF rect, QTextDocument doc, int posInDocument, QTextFormat format)
QSizeF intrinsicSize (self, QTextDocument doc, int posInDocument, QTextFormat format)
Detailed Description
该QTextObjectInterface类允许自定义文本对象的图形中QTextDocument秒。
文本对象描述的文本文档中的一个或多个元素的结构,例如,从HTML导入的图像是使用文本对象来实现。文本对象知道如何布局并绘制它的元素当一个文档被渲染。
Qt的可自定义文本对象通过注册一个自定义的被插入到文档中object type同QTextCharFormat。一个QTextObjectInterface也必须对这种类型实施,并registered与QAbstractTextDocumentLayout文档。当对象类型,而渲染遇到QTextDocument时,intrinsicSize()和drawObject()的接口的函数被调用。
下面的列表说明插入一个自定义的文本对象插入到文档中所需的步骤:
- Choose an objectType. The objectType is an integer with a value greater or equal to QTextFormat.UserObject.
- Create a QTextCharFormat object and set the object type to the chosen type using the setObjectType() function.
- Implement the QTextObjectInterface class.
- Call QAbstractTextDocumentLayout.registerHandler() with an instance of your QTextObjectInterface subclass to register your object type.
- Insert QChar.ObjectReplacementCharacter with the aforementioned QTextCharFormat of the chosen object type into the document. As mentioned, the functions of QTextObjectInterface intrinsicSize() and drawObject() will then be called with the QTextFormat as parameter whenever the replacement character is encountered.
一个类实现一个文本对象需要同时继承QObject和QTextObjectInterface 。QObject必须是继承了一流的。例如:
class SvgTextObject : public [QObject]($docs-qobject.html), public QTextObjectInterface
{
Q_OBJECT
Q_INTERFACES(QTextObjectInterface)
文本对象的数据通常存储在QTextCharFormat using QTextCharFormat.setProperty() ,然后用检索QTextCharFormat.property( ) 。
Warning:复制和粘贴操作忽略自定义的文本对象。
Method Documentation
QTextObjectInterface.__init__ (self)
QTextObjectInterface.__init__ (self, QTextObjectInterface)
QTextObjectInterface.drawObject (self, QPainter painter, QRectF rect, QTextDocument doc, int posInDocument, QTextFormat format)
这种方法是抽象的,应在任何子类中重新实现。
使用指定绘制这个文本对象painter。
该矩形的大小,rect,画中是先前计算的大小intrinsicSize( ) 。矩形的位置是相对于painter。
您还可以得到该文件(doc)和位置(posInDocument的)的format该文件中。
See also intrinsicSize( ) 。
QSizeF QTextObjectInterface.intrinsicSize (self, QTextDocument doc, int posInDocument, QTextFormat format)
[
这种方法是抽象的,应在任何子类中重新实现。
该intrinsicSize ( )函数返回所代表的文本对象的大小format给定的文件中(doc)在给定位置(posInDocument) 。
]($docs-qsizef.html)
计算出的大小将用于后续调用drawObject( )就本format。
See also drawObject( ) 。