Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
QTextObjectInterface Class Referenceabstract

The QTextObjectInterface class allows drawing of custom text objects in \l{QTextDocument}s. More...

#include <qabstracttextdocumentlayout.h>

+ Inheritance diagram for QTextObjectInterface:
+ Collaboration diagram for QTextObjectInterface:

Public Member Functions

virtual ~QTextObjectInterface ()
 Destroys this QTextObjectInterface.
 
virtual QSizeF intrinsicSize (QTextDocument *doc, int posInDocument, const QTextFormat &format)=0
 The intrinsicSize() function returns the size of the text object represented by format in the given document (doc) at the given position (posInDocument).
 
virtual void drawObject (QPainter *painter, const QRectF &rect, QTextDocument *doc, int posInDocument, const QTextFormat &format)=0
 Draws this text object using the specified painter.
 

Detailed Description

The QTextObjectInterface class allows drawing of custom text objects in \l{QTextDocument}s.

Since
4.5 \inmodule QtGui

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 \l{QTextCharFormat::objectType()}{object type} with QTextCharFormat. A QTextObjectInterface must also be implemented for this type and be \l{QAbstractTextDocumentLayout::registerHandler()}{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:

\list

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

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
QTextCharFormat, QTextLayout

Definition at line 102 of file qabstracttextdocumentlayout.h.

Constructor & Destructor Documentation

◆ ~QTextObjectInterface()

QTextObjectInterface::~QTextObjectInterface ( )
virtual

Destroys this QTextObjectInterface.

Definition at line 18 of file qabstracttextdocumentlayout.cpp.

Member Function Documentation

◆ drawObject()

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

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 format in that document.

See also
intrinsicSize()

Implemented in QQuickTextImageHandler, and QTextImageHandler.

Referenced by QQuickTextNodeEngine::addTextObject(), QTextDocumentLayoutPrivate::drawFlow(), and QAbstractTextDocumentLayout::drawInlineObject().

+ Here is the caller graph for this function:

◆ intrinsicSize()

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

The 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 drawObject() for this format.

See also
drawObject()

Implemented in QTextImageHandler, and QQuickTextImageHandler.

Referenced by QQuickTextNodeEngine::addTextObject(), QAbstractTextDocumentLayout::resizeInlineObject(), and QTextDocumentLayout::resizeInlineObject().

+ Here is the caller graph for this function:

The documentation for this class was generated from the following files: