QTextObjectInterface Class Reference |
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 |
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.
Destroys this QTextObjectInterface.
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().
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().
Cette page est une traduction d'une page de la documentation de Qt, écrite par Nokia Corporation and/or its subsidiary(-ies). Les éventuels problèmes résultant d'une mauvaise traduction ne sont pas imputables à Nokia. | Qt 4.6-snapshot | |
Copyright © 2012 Developpez LLC. Tous droits réservés Developpez LLC. Aucune reproduction, même partielle, ne peut être faite de ce site et de l'ensemble de son contenu : textes, documents et images sans l'autorisation expresse de Developpez LLC. Sinon, vous encourez selon la loi jusqu'à 3 ans de prison et jusqu'à 300 000 E de dommages et intérêts. Cette page est déposée à la SACD. | ||
Vous avez déniché une erreur ? Un bug ? Une redirection cassée ? Ou tout autre problème, quel qu'il soit ? Ou bien vous désirez participer à ce projet de traduction ? N'hésitez pas à nous contacter ou par MP ! |
Copyright © 2000-2012 - www.developpez.com