<?xml version="1.0" encoding="iso-8859-1"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd"> <html><head><title>QTextObjectInterface Class Reference</title><style>h3.fn,span.fn { margin-left: 1cm; text-indent: -1cm } a:link { color: #004faf; text-decoration: none } a:visited { color: #672967; text-decoration: none } td.postheader { font-family: sans-serif } tr.address { font-family: sans-serif } body { background: #ffffff; color: black; } </style></head><body><table border="0" cellpadding="0" cellspacing="0" width="100%"><tr /><td align="left" valign="top" width="32"><img align="left" border="0" height="32" src="images/rb-logo.png" width="32" /></td><td width="1">  </td><td class="postheader" valign="center"><a href="index.html"><font color="#004faf">Home</font></a> · <a href="classes.html"><font color="#004faf">All Classes</font></a> · <a href="modules.html"><font color="#004faf">Modules</font></a></td></table><h1 align="center">QTextObjectInterface Class Reference<br /><sup><sup>[<a href="qtgui.html">QtGui</a> module]</sup></sup></h1><p>The QTextObjectInterface class allows drawing of custom text objects in <a href="qtextdocument.html">QTextDocument</a>s. <a href="#details">More...</a></p> <p>Inherited by <a href="qpytextobject.html">QPyTextObject</a>.</p><h3>Methods</h3><ul><li><div class="fn" /><b><a href="qtextobjectinterface.html#QTextObjectInterface">__init__</a></b> (<i>self</i>)</li><li><div class="fn" /><b><a href="qtextobjectinterface.html#QTextObjectInterface-2">__init__</a></b> (<i>self</i>, QTextObjectInterface)</li><li><div class="fn" /><b><a href="qtextobjectinterface.html#drawObject">drawObject</a></b> (<i>self</i>, QPainter <i>painter</i>, QRectF <i>rect</i>, QTextDocument <i>doc</i>, int <i>posInDocument</i>, QTextFormat <i>format</i>)</li><li><div class="fn" />QSizeF <b><a href="qtextobjectinterface.html#intrinsicSize">intrinsicSize</a></b> (<i>self</i>, QTextDocument <i>doc</i>, int <i>posInDocument</i>, QTextFormat <i>format</i>)</li></ul><a name="details" /><hr /><h2>Detailed Description</h2><p>The QTextObjectInterface class allows drawing of custom text objects in <a href="qtextdocument.html">QTextDocument</a>s.</p> <p>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.</p> <p>Qt allows custom text objects to be inserted into a document by registering a custom <a href="qtextformat.html#objectType">object type</a> with <a href="qtextcharformat.html">QTextCharFormat</a>. A QTextObjectInterface must also be implemented for this type and be <a href="qabstracttextdocumentlayout.html#registerHandler">registered</a> with the <a href="qabstracttextdocumentlayout.html">QAbstractTextDocumentLayout</a> of the document. When the object type is encountered while rendering a <a href="qtextdocument.html">QTextDocument</a>, the <a href="qtextobjectinterface.html#intrinsicSize">intrinsicSize</a>() and <a href="qtextobjectinterface.html#drawObject">drawObject</a>() functions of the interface are called.</p> <p>The following list explains the required steps of inserting a custom text object into a document:</p> <ul> <li>Choose an <i>objectType</i>. The <i>objectType</i> is an integer with a value greater or equal to <a href="qtextformat.html#ObjectTypes-enum">QTextFormat.UserObject</a>.</li> <li>Create a <a href="qtextcharformat.html">QTextCharFormat</a> object and set the object type to the chosen type using the setObjectType() function.</li> <li>Implement the QTextObjectInterface class.</li> <li>Call <a href="qabstracttextdocumentlayout.html#registerHandler">QAbstractTextDocumentLayout.registerHandler</a>() with an instance of your QTextObjectInterface subclass to register your object type.</li> <li>Insert <a href="qchar.html#SpecialCharacter-enum">QChar.ObjectReplacementCharacter</a> with the aforementioned <a href="qtextcharformat.html">QTextCharFormat</a> of the chosen object type into the document. As mentioned, the functions of QTextObjectInterface <a href="qtextobjectinterface.html#intrinsicSize">intrinsicSize()</a> and <a href="qtextobjectinterface.html#drawObject">drawObject()</a> will then be called with the <a href="qtextformat.html">QTextFormat</a> as parameter whenever the replacement character is encountered.</li> </ul> <p>A class implementing a text object needs to inherit both <a href="qobject.html">QObject</a> and QTextObjectInterface. <a href="qobject.html">QObject</a> must be the first class inherited. For instance:</p> <pre class="cpp"> <span class="keyword">class</span> SvgTextObject : <span class="keyword">public</span> <span class="type"><a href="qobject.html">QObject</a></span><span class="operator">,</span> <span class="keyword">public</span> <span class="type">QTextObjectInterface</span> { Q_OBJECT Q_INTERFACES(<span class="type">QTextObjectInterface</span>) </pre> <p>The data of a text object is usually stored in the <a href="qtextcharformat.html">QTextCharFormat</a> using <a href="qtextformat.html#setProperty">QTextCharFormat.setProperty</a>(), and then retrieved with <a href="qtextformat.html#property">QTextCharFormat.property</a>().</p> <p><b>Warning:</b> Copy and Paste operations ignore custom text objects.</p> <hr /><h2>Method Documentation</h2><h3 class="fn"><a name="QTextObjectInterface" />QTextObjectInterface.__init__ (<i>self</i>)</h3><h3 class="fn"><a name="QTextObjectInterface-2" />QTextObjectInterface.__init__ (<i>self</i>, <a href="qtextobjectinterface.html">QTextObjectInterface</a>)</h3><h3 class="fn"><a name="drawObject" />QTextObjectInterface.drawObject (<i>self</i>, <a href="qpainter.html">QPainter</a> <i>painter</i>, <a href="qrectf.html">QRectF</a> <i>rect</i>, <a href="qtextdocument.html">QTextDocument</a> <i>doc</i>, int <i>posInDocument</i>, <a href="qtextformat.html">QTextFormat</a> <i>format</i>)</h3><p>This method is abstract and should be reimplemented in any sub-class.</p><p>Draws this text object using the specified <i>painter</i>.</p> <p>The size of the rectangle, <i>rect</i>, to draw in is the size previously calculated by <a href="qtextobjectinterface.html#intrinsicSize">intrinsicSize</a>(). The rectangles position is relative to the <i>painter</i>.</p> <p>You also get the document (<i>doc</i>) and the position (<i>posInDocument</i>) of the <i>format</i> in that document.</p> <p><b>See also</b> <a href="qtextobjectinterface.html#intrinsicSize">intrinsicSize</a>().</p> <h3 class="fn"><a name="intrinsicSize" /><a href="qsizef.html">QSizeF</a> QTextObjectInterface.intrinsicSize (<i>self</i>, <a href="qtextdocument.html">QTextDocument</a> <i>doc</i>, int <i>posInDocument</i>, <a href="qtextformat.html">QTextFormat</a> <i>format</i>)</h3><p>This method is abstract and should be reimplemented in any sub-class.</p><p>The intrinsicSize() function returns the size of the text object represented by <i>format</i> in the given document (<i>doc</i>) at the given position (<i>posInDocument</i>).</p> <p>The size calculated will be used for subsequent calls to <a href="qtextobjectinterface.html#drawObject">drawObject</a>() for this <i>format</i>.</p> <p><b>See also</b> <a href="qtextobjectinterface.html#drawObject">drawObject</a>().</p> <address><hr /><div align="center"><table border="0" cellspacing="0" width="100%"><tr class="address"><td align="left" width="25%">PyQt 4.10.3 for X11</td><td align="center" width="50%">Copyright © <a href="http://www.riverbankcomputing.com">Riverbank Computing Ltd</a> and <a href="http://www.qtsoftware.com">Nokia</a> 2012</td><td align="right" width="25%">Qt 4.8.5</td></tr></table></div></address></body></html>