<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE html> <html lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <!-- qtextdocumentfragment.cpp --> <title>QTextDocumentFragment Class | Qt GUI 5.12.6</title> <link rel="stylesheet" type="text/css" href="style/offline-simple.css" /> <script type="text/javascript"> document.getElementsByTagName("link").item(0).setAttribute("href", "style/offline.css"); // loading style sheet breaks anchors that were jumped to before // so force jumping to anchor again setTimeout(function() { var anchor = location.hash; // need to jump to different anchor first (e.g. none) location.hash = "#"; setTimeout(function() { location.hash = anchor; }, 0); }, 0); </script> </head> <body> <div class="header" id="qtdocheader"> <div class="main"> <div class="main-rounded"> <div class="navigationbar"> <table><tr> <td >Qt 5.12</td><td ><a href="qtgui-index.html">Qt GUI</a></td><td ><a href="qtgui-module.html">C++ Classes</a></td><td >QTextDocumentFragment</td></tr></table><table class="buildversion"><tr> <td id="buildversion" width="100%" align="right"><a href="qtgui-index.html">Qt 5.12.6 Reference Documentation</a></td> </tr></table> </div> </div> <div class="content"> <div class="line"> <div class="content mainContent"> <div class="sidebar"> <div class="toc"> <h3><a name="toc">Contents</a></h3> <ul> <li class="level1"><a href="#public-functions">Public Functions</a></li> <li class="level1"><a href="#static-public-members">Static Public Members</a></li> <li class="level1"><a href="#details">Detailed Description</a></li> </ul> </div> <div class="sidebar-content" id="sidebar-content"></div></div> <h1 class="title">QTextDocumentFragment Class</h1> <!-- $$$QTextDocumentFragment-brief --> <p>The <a href="qtextdocumentfragment.html">QTextDocumentFragment</a> class represents a piece of formatted text from a <a href="qtextdocument.html">QTextDocument</a>. <a href="#details">More...</a></p> <!-- @@@QTextDocumentFragment --> <div class="table"><table class="alignedsummary"> <tr><td class="memItemLeft rightAlign topAlign"> Header:</td><td class="memItemRight bottomAlign"> <span class="preprocessor">#include <QTextDocumentFragment></span> </td></tr><tr><td class="memItemLeft rightAlign topAlign"> qmake:</td><td class="memItemRight bottomAlign"> QT += gui</td></tr></table></div><ul> <li><a href="qtextdocumentfragment-members.html">List of all members, including inherited members</a></li> </ul> <p><b>Note:</b> All functions in this class are reentrant.</p> <a name="public-functions"></a> <h2 id="public-functions">Public Functions</h2> <div class="table"><table class="alignedsummary"> <tr><td class="memItemLeft rightAlign topAlign"> </td><td class="memItemRight bottomAlign"><b><a href="qtextdocumentfragment.html#QTextDocumentFragment">QTextDocumentFragment</a></b>()</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> </td><td class="memItemRight bottomAlign"><b><a href="qtextdocumentfragment.html#QTextDocumentFragment-1">QTextDocumentFragment</a></b>(const QTextDocument *<i>document</i>)</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> </td><td class="memItemRight bottomAlign"><b><a href="qtextdocumentfragment.html#QTextDocumentFragment-2">QTextDocumentFragment</a></b>(const QTextCursor &<i>cursor</i>)</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> </td><td class="memItemRight bottomAlign"><b><a href="qtextdocumentfragment.html#QTextDocumentFragment-3">QTextDocumentFragment</a></b>(const QTextDocumentFragment &<i>other</i>)</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> </td><td class="memItemRight bottomAlign"><b><a href="qtextdocumentfragment.html#dtor.QTextDocumentFragment">~QTextDocumentFragment</a></b>()</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> bool </td><td class="memItemRight bottomAlign"><b><a href="qtextdocumentfragment.html#isEmpty">isEmpty</a></b>() const</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> QString </td><td class="memItemRight bottomAlign"><b><a href="qtextdocumentfragment.html#toHtml">toHtml</a></b>(const QByteArray &<i>encoding</i> = QByteArray()) const</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> QString </td><td class="memItemRight bottomAlign"><b><a href="qtextdocumentfragment.html#toPlainText">toPlainText</a></b>() const</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> QTextDocumentFragment &</td><td class="memItemRight bottomAlign"><b><a href="qtextdocumentfragment.html#operator-eq">operator=</a></b>(const QTextDocumentFragment &<i>other</i>)</td></tr> </table></div> <a name="static-public-members"></a> <h2 id="static-public-members">Static Public Members</h2> <div class="table"><table class="alignedsummary"> <tr><td class="memItemLeft rightAlign topAlign"> QTextDocumentFragment </td><td class="memItemRight bottomAlign"><b><a href="qtextdocumentfragment.html#fromHtml">fromHtml</a></b>(const QString &<i>text</i>)</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> QTextDocumentFragment </td><td class="memItemRight bottomAlign"><b><a href="qtextdocumentfragment.html#fromHtml-1">fromHtml</a></b>(const QString &<i>text</i>, const QTextDocument *<i>resourceProvider</i>)</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> QTextDocumentFragment </td><td class="memItemRight bottomAlign"><b><a href="qtextdocumentfragment.html#fromPlainText">fromPlainText</a></b>(const QString &<i>plainText</i>)</td></tr> </table></div> <a name="details"></a> <!-- $$$QTextDocumentFragment-description --> <div class="descr"> <h2 id="details">Detailed Description</h2> <p>The <a href="qtextdocumentfragment.html">QTextDocumentFragment</a> class represents a piece of formatted text from a <a href="qtextdocument.html">QTextDocument</a>.</p> <p>A <a href="qtextdocumentfragment.html">QTextDocumentFragment</a> 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> </div> <!-- @@@QTextDocumentFragment --> <div class="func"> <h2>Member Function Documentation</h2> <!-- $$$QTextDocumentFragment[overload1]$$$QTextDocumentFragment --> <h3 class="fn" id="QTextDocumentFragment"><a name="QTextDocumentFragment"></a>QTextDocumentFragment::<span class="name">QTextDocumentFragment</span>()</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> <!-- @@@QTextDocumentFragment --> <!-- $$$QTextDocumentFragment$$$QTextDocumentFragmentconstQTextDocument* --> <h3 class="fn" id="QTextDocumentFragment-1"><a name="QTextDocumentFragment-1"></a>QTextDocumentFragment::<span class="name">QTextDocumentFragment</span>(const <span class="type"><a href="qtextdocument.html">QTextDocument</a></span> *<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> <!-- @@@QTextDocumentFragment --> <!-- $$$QTextDocumentFragment$$$QTextDocumentFragmentconstQTextCursor& --> <h3 class="fn" id="QTextDocumentFragment-2"><a name="QTextDocumentFragment-2"></a>QTextDocumentFragment::<span class="name">QTextDocumentFragment</span>(const <span class="type"><a href="qtextcursor.html">QTextCursor</a></span> &<i>cursor</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> <!-- @@@QTextDocumentFragment --> <!-- $$$QTextDocumentFragment$$$QTextDocumentFragmentconstQTextDocumentFragment& --> <h3 class="fn" id="QTextDocumentFragment-3"><a name="QTextDocumentFragment-3"></a>QTextDocumentFragment::<span class="name">QTextDocumentFragment</span>(const <span class="type"><a href="qtextdocumentfragment.html#QTextDocumentFragment">QTextDocumentFragment</a></span> &<i>other</i>)</h3> <p>Copy constructor. Creates a copy of the <i>other</i> fragment.</p> <!-- @@@QTextDocumentFragment --> <!-- $$$~QTextDocumentFragment[overload1]$$$~QTextDocumentFragment --> <h3 class="fn" id="dtor.QTextDocumentFragment"><a name="dtor.QTextDocumentFragment"></a>QTextDocumentFragment::<span class="name">~QTextDocumentFragment</span>()</h3> <p>Destroys the document fragment.</p> <!-- @@@~QTextDocumentFragment --> <!-- $$$fromHtml[overload1]$$$fromHtmlconstQString& --> <h3 class="fn" id="fromHtml"><a name="fromHtml"></a><code>[static] </code><span class="type"><a href="qtextdocumentfragment.html#QTextDocumentFragment">QTextDocumentFragment</a></span> QTextDocumentFragment::<span class="name">fromHtml</span>(const <span class="type"><a href="../qtcore/qstring.html">QString</a></span> &<i>text</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> <!-- @@@fromHtml --> <!-- $$$fromHtml$$$fromHtmlconstQString&constQTextDocument* --> <h3 class="fn" id="fromHtml-1"><a name="fromHtml-1"></a><code>[static] </code><span class="type"><a href="qtextdocumentfragment.html#QTextDocumentFragment">QTextDocumentFragment</a></span> QTextDocumentFragment::<span class="name">fromHtml</span>(const <span class="type"><a href="../qtcore/qstring.html">QString</a></span> &<i>text</i>, const <span class="type"><a href="qtextdocument.html">QTextDocument</a></span> *<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> <!-- @@@fromHtml --> <!-- $$$fromPlainText[overload1]$$$fromPlainTextconstQString& --> <h3 class="fn" id="fromPlainText"><a name="fromPlainText"></a><code>[static] </code><span class="type"><a href="qtextdocumentfragment.html#QTextDocumentFragment">QTextDocumentFragment</a></span> QTextDocumentFragment::<span class="name">fromPlainText</span>(const <span class="type"><a href="../qtcore/qstring.html">QString</a></span> &<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> <!-- @@@fromPlainText --> <!-- $$$isEmpty[overload1]$$$isEmpty --> <h3 class="fn" id="isEmpty"><a name="isEmpty"></a><span class="type">bool</span> QTextDocumentFragment::<span class="name">isEmpty</span>() const</h3> <p>Returns <code>true</code> if the fragment is empty; otherwise returns <code>false</code>.</p> <!-- @@@isEmpty --> <!-- $$$toHtml[overload1]$$$toHtmlconstQByteArray& --> <h3 class="fn" id="toHtml"><a name="toHtml"></a><span class="type"><a href="../qtcore/qstring.html">QString</a></span> QTextDocumentFragment::<span class="name">toHtml</span>(const <span class="type"><a href="../qtcore/qbytearray.html">QByteArray</a></span> &<i>encoding</i> = QByteArray()) const</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="../qtcore/qtextcodec.html">QTextCodec</a>.</p> <!-- @@@toHtml --> <!-- $$$toPlainText[overload1]$$$toPlainText --> <h3 class="fn" id="toPlainText"><a name="toPlainText"></a><span class="type"><a href="../qtcore/qstring.html">QString</a></span> QTextDocumentFragment::<span class="name">toPlainText</span>() const</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> <!-- @@@toPlainText --> <!-- $$$operator=[overload1]$$$operator=constQTextDocumentFragment& --> <h3 class="fn" id="operator-eq"><a name="operator-eq"></a><span class="type"><a href="qtextdocumentfragment.html#QTextDocumentFragment">QTextDocumentFragment</a></span> &QTextDocumentFragment::<span class="name">operator=</span>(const <span class="type"><a href="qtextdocumentfragment.html#QTextDocumentFragment">QTextDocumentFragment</a></span> &<i>other</i>)</h3> <p>Assigns the <i>other</i> fragment to this fragment.</p> <!-- @@@operator= --> </div> </div> </div> </div> </div> </div> <div class="footer"> <p> <acronym title="Copyright">©</acronym> 2019 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners.<br/> The documentation provided herein is licensed under the terms of the <a href="http://www.gnu.org/licenses/fdl.html">GNU Free Documentation License version 1.3</a> as published by the Free Software Foundation.<br/> Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners. </p> </div> </body> </html>