<?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>QTextDocumentFragment 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">QTextDocumentFragment Class Reference<br /><sup><sup>[<a href="qtgui.html">QtGui</a> module]</sup></sup></h1><p>The QTextDocumentFragment class represents a piece of formatted text from a <a href="qtextdocument.html">QTextDocument</a>. <a href="#details">More...</a></p> <h3>Methods</h3><ul><li><div class="fn" /><b><a href="qtextdocumentfragment.html#QTextDocumentFragment">__init__</a></b> (<i>self</i>)</li><li><div class="fn" /><b><a href="qtextdocumentfragment.html#QTextDocumentFragment-2">__init__</a></b> (<i>self</i>, QTextDocument <i>document</i>)</li><li><div class="fn" /><b><a href="qtextdocumentfragment.html#QTextDocumentFragment-3">__init__</a></b> (<i>self</i>, QTextCursor <i>range</i>)</li><li><div class="fn" /><b><a href="qtextdocumentfragment.html#QTextDocumentFragment-4">__init__</a></b> (<i>self</i>, QTextDocumentFragment <i>rhs</i>)</li><li><div class="fn" />bool <b><a href="qtextdocumentfragment.html#isEmpty">isEmpty</a></b> (<i>self</i>)</li><li><div class="fn" />QString <b><a href="qtextdocumentfragment.html#toHtml">toHtml</a></b> (<i>self</i>)</li><li><div class="fn" />QString <b><a href="qtextdocumentfragment.html#toHtml-2">toHtml</a></b> (<i>self</i>, QByteArray <i>encoding</i>)</li><li><div class="fn" />QString <b><a href="qtextdocumentfragment.html#toPlainText">toPlainText</a></b> (<i>self</i>)</li></ul><h3>Static Methods</h3><ul><li><div class="fn" />QTextDocumentFragment <b><a href="qtextdocumentfragment.html#fromHtml">fromHtml</a></b> (QString <i>html</i>)</li><li><div class="fn" />QTextDocumentFragment <b><a href="qtextdocumentfragment.html#fromHtml-2">fromHtml</a></b> (QString <i>html</i>, QTextDocument <i>resourceProvider</i>)</li><li><div class="fn" />QTextDocumentFragment <b><a href="qtextdocumentfragment.html#fromPlainText">fromPlainText</a></b> (QString <i>plainText</i>)</li></ul><a name="details" /><hr /><h2>Detailed Description</h2><p>The QTextDocumentFragment class represents a piece of formatted text from a <a href="qtextdocument.html">QTextDocument</a>.</p> <p>A QTextDocumentFragment is a fragment of rich text, that can be inserted into a <a href="qtextdocument.html">QTextDocument</a>. A document fragment can be created from a <a href="qtextdocument.html">QTextDocument</a>, from a <a href="qtextcursor.html">QTextCursor</a>'s selection, or from another document fragment. Document fragments can also be created by the static functions, <a href="qtextdocumentfragment.html#fromPlainText">fromPlainText</a>() and <a href="qtextdocumentfragment.html#fromHtml">fromHtml</a>().</p> <p>The contents of a document fragment can be obtained as plain text by using the <a href="qtextdocumentfragment.html#toPlainText">toPlainText</a>() function, or it can be obtained as HTML with <a href="qtextdocumentfragment.html#toHtml">toHtml</a>().</p> <hr /><h2>Method Documentation</h2><h3 class="fn"><a name="QTextDocumentFragment" />QTextDocumentFragment.__init__ (<i>self</i>)</h3><p>Constructs an empty <a href="qtextdocumentfragment.html">QTextDocumentFragment</a>.</p> <p><b>See also</b> <a href="qtextdocumentfragment.html#isEmpty">isEmpty</a>().</p> <h3 class="fn"><a name="QTextDocumentFragment-2" />QTextDocumentFragment.__init__ (<i>self</i>, <a href="qtextdocument.html">QTextDocument</a> <i>document</i>)</h3><p>Converts the given <i>document</i> into a <a href="qtextdocumentfragment.html">QTextDocumentFragment</a>. Note that the <a href="qtextdocumentfragment.html">QTextDocumentFragment</a> only stores the document contents, not meta information like the document's title.</p> <h3 class="fn"><a name="QTextDocumentFragment-3" />QTextDocumentFragment.__init__ (<i>self</i>, <a href="qtextcursor.html">QTextCursor</a> <i>range</i>)</h3><p>Creates a <a href="qtextdocumentfragment.html">QTextDocumentFragment</a> from the <i>cursor</i>'s selection. If the cursor doesn't have a selection, the created fragment is empty.</p> <p><b>See also</b> <a href="qtextdocumentfragment.html#isEmpty">isEmpty</a>() and <a href="qtextcursor.html#selection">QTextCursor.selection</a>().</p> <h3 class="fn"><a name="QTextDocumentFragment-4" />QTextDocumentFragment.__init__ (<i>self</i>, <a href="qtextdocumentfragment.html">QTextDocumentFragment</a> <i>rhs</i>)</h3><p>Copy constructor. Creates a copy of the <i>other</i> fragment.</p> <h3 class="fn"><a name="fromHtml" /><a href="qtextdocumentfragment.html">QTextDocumentFragment</a> QTextDocumentFragment.fromHtml (QString <i>html</i>)</h3><p>Returns a <a href="qtextdocumentfragment.html">QTextDocumentFragment</a> based on the arbitrary piece of HTML in the given <i>text</i>. The formatting is preserved as much as possible; for example, "<b>bold</b>" will become a document fragment with the text "bold" with a bold character format.</p> <h3 class="fn"><a name="fromHtml-2" /><a href="qtextdocumentfragment.html">QTextDocumentFragment</a> QTextDocumentFragment.fromHtml (QString <i>html</i>, <a href="qtextdocument.html">QTextDocument</a> <i>resourceProvider</i>)</h3><p>Returns a <a href="qtextdocumentfragment.html">QTextDocumentFragment</a> based on the arbitrary piece of HTML in the given <i>text</i>. The formatting is preserved as much as possible; for example, "<b>bold</b>" will become a document fragment with the text "bold" with a bold character format.</p> <p>If the provided HTML contains references to external resources such as imported style sheets, then they will be loaded through the <i>resourceProvider</i>.</p> <p>This function was introduced in Qt 4.2.</p> <h3 class="fn"><a name="fromPlainText" /><a href="qtextdocumentfragment.html">QTextDocumentFragment</a> QTextDocumentFragment.fromPlainText (QString <i>plainText</i>)</h3><p>Returns a document fragment that contains the given <i>plainText</i>.</p> <p>When inserting such a fragment into a <a href="qtextdocument.html">QTextDocument</a> the current char format of the <a href="qtextcursor.html">QTextCursor</a> used for insertion is used as format for the text.</p> <h3 class="fn"><a name="isEmpty" />bool QTextDocumentFragment.isEmpty (<i>self</i>)</h3><p>Returns true if the fragment is empty; otherwise returns false.</p> <h3 class="fn"><a name="toHtml" />QString QTextDocumentFragment.toHtml (<i>self</i>)</h3><p>Returns the contents of the document fragment as HTML, using the specified <i>encoding</i> (e.g., "UTF-8", "ISO 8859-1").</p> <p>This function was introduced in Qt 4.2.</p> <p><b>See also</b> <a href="qtextdocumentfragment.html#toPlainText">toPlainText</a>(), <a href="qtextdocument.html#toHtml">QTextDocument.toHtml</a>(), and <a href="qtextcodec.html">QTextCodec</a>.</p> <h3 class="fn"><a name="toHtml-2" />QString QTextDocumentFragment.toHtml (<i>self</i>, <a href="qbytearray.html">QByteArray</a> <i>encoding</i>)</h3><p>This is an overloaded function.</p> <h3 class="fn"><a name="toPlainText" />QString QTextDocumentFragment.toPlainText (<i>self</i>)</h3><p>Returns the document fragment's text as plain text (i.e. with no formatting information).</p> <p><b>See also</b> <a href="qtextdocumentfragment.html#toHtml">toHtml</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>