QTextObjectInterface Class

The QTextObjectInterface class allows drawing of custom text objects in QTextDocuments. More...

Header: #include <QTextObjectInterface>
qmake: QT += gui
Since: Qt 4.5

Public Functions

virtual ~QTextObjectInterface()
virtual void drawObject(QPainter *painter, const QRectF &rect, QTextDocument *doc, int posInDocument, const QTextFormat &format) = 0
virtual QSizeF intrinsicSize(QTextDocument *doc, int posInDocument, const QTextFormat &format) = 0

Detailed Description

The QTextObjectInterface class allows drawing of custom text objects in QTextDocuments.

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 QTextCharFormat. A QTextObjectInterface must also be implemented for this type and be registered with the QAbstractTextDocumentLayout of 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:

A class implementing a text object needs to inherit both QObject and QTextObjectInterface. QObject must be the first class inherited. For instance:


  class SvgTextObject : public QObject, public QTextObjectInterface
  {
      Q_OBJECT
      Q_INTERFACES(QTextObjectInterface)

The data of a text object is usually stored in the QTextCharFormat using QTextCharFormat::setProperty(), and then retrieved with QTextCharFormat::property().

Warning: Copy and Paste operations ignore custom text objects.

See also Text Object Example, QTextCharFormat, and QTextLayout.

Member Function Documentation

[virtual] QTextObjectInterface::~QTextObjectInterface()

Destroys the instance of QTextObjectInterface. The destructor is virtual.

[pure virtual] void QTextObjectInterface::drawObject(QPainter *painter, const QRectF &rect, QTextDocument *doc, int posInDocument, const QTextFormat &format)

[pure virtual] QSizeF QTextObjectInterface::intrinsicSize(QTextDocument *doc, int posInDocument, const QTextFormat &format)