<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en_US" lang="en_US"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <!-- qtextdocumentfragment.cpp --> <title>Qt 4.8: QTextDocumentFragment Class Reference</title> <link rel="stylesheet" type="text/css" href="style/style.css" /> <script src="scripts/jquery.js" type="text/javascript"></script> <script src="scripts/functions.js" type="text/javascript"></script> <link rel="stylesheet" type="text/css" href="style/superfish.css" /> <link rel="stylesheet" type="text/css" href="style/narrow.css" /> <!--[if IE]> <meta name="MSSmartTagsPreventParsing" content="true"> <meta http-equiv="imagetoolbar" content="no"> <![endif]--> <!--[if lt IE 7]> <link rel="stylesheet" type="text/css" href="style/style_ie6.css"> <![endif]--> <!--[if IE 7]> <link rel="stylesheet" type="text/css" href="style/style_ie7.css"> <![endif]--> <!--[if IE 8]> <link rel="stylesheet" type="text/css" href="style/style_ie8.css"> <![endif]--> <script src="scripts/superfish.js" type="text/javascript"></script> <script src="scripts/narrow.js" type="text/javascript"></script> </head> <body class="" onload="CheckEmptyAndLoadList();"> <div class="header" id="qtdocheader"> <div class="content"> <div id="nav-logo"> <a href="index.html">Home</a></div> <a href="index.html" class="qtref"><span>Qt Reference Documentation</span></a> <div id="narrowsearch"></div> <div id="nav-topright"> <ul> <li class="nav-topright-home"><a href="http://qt.digia.com/">Qt HOME</a></li> <li class="nav-topright-dev"><a href="http://qt-project.org/">DEV</a></li> <li class="nav-topright-doc nav-topright-doc-active"><a href="http://qt-project.org/doc/"> DOC</a></li> <li class="nav-topright-blog"><a href="http://blog.qt.digia.com/">BLOG</a></li> </ul> </div> <div id="shortCut"> <ul> <li class="shortCut-topleft-inactive"><span><a href="index.html">Qt 4.8</a></span></li> <li class="shortCut-topleft-active"><a href="http://qt-project.org/doc/">ALL VERSIONS </a></li> </ul> </div> <ul class="sf-menu" id="narrowmenu"> <li><a href="#">API Lookup</a> <ul> <li><a href="classes.html">Class index</a></li> <li><a href="functions.html">Function index</a></li> <li><a href="modules.html">Modules</a></li> <li><a href="namespaces.html">Namespaces</a></li> <li><a href="qtglobal.html">Global Declarations</a></li> <li><a href="qdeclarativeelements.html">QML elements</a></li> </ul> </li> <li><a href="#">Qt Topics</a> <ul> <li><a href="qt-basic-concepts.html">Programming with Qt</a></li> <li><a href="qtquick.html">Device UIs & Qt Quick</a></li> <li><a href="qt-gui-concepts.html">UI Design with Qt</a></li> <li><a href="supported-platforms.html">Supported Platforms</a></li> <li><a href="technology-apis.html">Qt and Key Technologies</a></li> <li><a href="best-practices.html">How-To's and Best Practices</a></li> </ul> </li> <li><a href="#">Examples</a> <ul> <li><a href="all-examples.html">Examples</a></li> <li><a href="tutorials.html">Tutorials</a></li> <li><a href="demos.html">Demos</a></li> <li><a href="qdeclarativeexamples.html">QML Examples</a></li> </ul> </li> </ul> </div> </div> <div class="wrapper"> <div class="hd"> <span></span> </div> <div class="bd group"> <div class="sidebar"> <div class="searchlabel"> Search index:</div> <div class="search" id="sidebarsearch"> <form id="qtdocsearch" action="" onsubmit="return false;"> <fieldset> <input type="text" name="searchstring" id="pageType" value="" /> <div id="resultdialog"> <a href="#" id="resultclose">Close</a> <p id="resultlinks" class="all"><a href="#" id="showallresults">All</a> | <a href="#" id="showapiresults">API</a> | <a href="#" id="showarticleresults">Articles</a> | <a href="#" id="showexampleresults">Examples</a></p> <p id="searchcount" class="all"><span id="resultcount"></span><span id="apicount"></span><span id="articlecount"></span><span id="examplecount"></span> results:</p> <ul id="resultlist" class="all"> </ul> </div> </fieldset> </form> </div> <div class="box first bottombar" id="lookup"> <h2 title="API Lookup"><span></span> API Lookup</h2> <div id="list001" class="list"> <ul id="ul001" > <li class="defaultLink"><a href="classes.html">Class index</a></li> <li class="defaultLink"><a href="functions.html">Function index</a></li> <li class="defaultLink"><a href="modules.html">Modules</a></li> <li class="defaultLink"><a href="namespaces.html">Namespaces</a></li> <li class="defaultLink"><a href="qtglobal.html">Global Declarations</a></li> <li class="defaultLink"><a href="qdeclarativeelements.html">QML elements</a></li> </ul> </div> </div> <div class="box bottombar" id="topics"> <h2 title="Qt Topics"><span></span> Qt Topics</h2> <div id="list002" class="list"> <ul id="ul002" > <li class="defaultLink"><a href="qt-basic-concepts.html">Programming with Qt</a></li> <li class="defaultLink"><a href="qtquick.html">Device UIs & Qt Quick</a></li> <li class="defaultLink"><a href="qt-gui-concepts.html">UI Design with Qt</a></li> <li class="defaultLink"><a href="supported-platforms.html">Supported Platforms</a></li> <li class="defaultLink"><a href="technology-apis.html">Qt and Key Technologies</a></li> <li class="defaultLink"><a href="best-practices.html">How-To's and Best Practices</a></li> </ul> </div> </div> <div class="box" id="examples"> <h2 title="Examples"><span></span> Examples</h2> <div id="list003" class="list"> <ul id="ul003"> <li class="defaultLink"><a href="all-examples.html">Examples</a></li> <li class="defaultLink"><a href="tutorials.html">Tutorials</a></li> <li class="defaultLink"><a href="demos.html">Demos</a></li> <li class="defaultLink"><a href="qdeclarativeexamples.html">QML Examples</a></li> </ul> </div> </div> </div> <div class="wrap"> <div class="toolbar"> <div class="breadcrumb toolblock"> <ul> <li class="first"><a href="index.html">Home</a></li> <!-- Breadcrumbs go here --> <li><a href="modules.html">Modules</a></li> <li><a href="qtgui.html">QtGui</a></li> <li>QTextDocumentFragment</li> </ul> </div> <div class="toolbuttons toolblock"> <ul> <li id="smallA" class="t_button">A</li> <li id="medA" class="t_button active">A</li> <li id="bigA" class="t_button">A</li> <li id="print" class="t_button"><a href="javascript:this.print();"> <span>Print</span></a></li> </ul> </div> </div> <div class="content mainContent"> <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> <h1 class="title">QTextDocumentFragment Class Reference</h1> <!-- $$$QTextDocumentFragment-brief --> <p>The QTextDocumentFragment class represents a piece of formatted text from a <a href="qtextdocument.html">QTextDocument</a>. <a href="#details">More...</a></p> <!-- @@@QTextDocumentFragment --> <pre class="cpp"> <span class="preprocessor">#include <QTextDocumentFragment></span></pre><p><b>Note:</b> All functions in this class are <a href="threads-reentrancy.html#reentrant">reentrant</a>.</p> <ul> <li><a href="qtextdocumentfragment-members.html">List of all members, including inherited members</a></li> </ul> <a name="public-functions"></a> <h2>Public Functions</h2> <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-2">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-3">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-4">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> ) const</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> QString </td><td class="memItemRight bottomAlign"><b><a href="qtextdocumentfragment.html#toHtml-2">toHtml</a></b> () 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> <a name="static-public-members"></a> <h2>Static Public Members</h2> <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-2">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> <a name="details"></a> <!-- $$$QTextDocumentFragment-description --> <div class="descr"> <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> </div> <!-- @@@QTextDocumentFragment --> <div class="func"> <h2>Member Function Documentation</h2> <!-- $$$QTextDocumentFragment[overload1]$$$QTextDocumentFragment --> <h3 class="fn"><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"><a name="QTextDocumentFragment-2"></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"><a name="QTextDocumentFragment-3"></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"><a name="QTextDocumentFragment-4"></a>QTextDocumentFragment::<span class="name">QTextDocumentFragment</span> ( const <span class="type">QTextDocumentFragment</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"><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"><a name="fromHtml"></a><span class="type">QTextDocumentFragment</span> QTextDocumentFragment::<span class="name">fromHtml</span> ( const <span class="type"><a href="qstring.html">QString</a></span> & <i>text</i> )<tt> [static]</tt></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"><a name="fromHtml-2"></a><span class="type">QTextDocumentFragment</span> QTextDocumentFragment::<span class="name">fromHtml</span> ( const <span class="type"><a href="qstring.html">QString</a></span> & <i>text</i>, const <span class="type"><a href="qtextdocument.html">QTextDocument</a></span> * <i>resourceProvider</i> )<tt> [static]</tt></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"><a name="fromPlainText"></a><span class="type">QTextDocumentFragment</span> QTextDocumentFragment::<span class="name">fromPlainText</span> ( const <span class="type"><a href="qstring.html">QString</a></span> & <i>plainText</i> )<tt> [static]</tt></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"><a name="isEmpty"></a><span class="type">bool</span> QTextDocumentFragment::<span class="name">isEmpty</span> () const</h3> <p>Returns true if the fragment is empty; otherwise returns false.</p> <!-- @@@isEmpty --> <!-- $$$toHtml[overload1]$$$toHtmlconstQByteArray& --> <h3 class="fn"><a name="toHtml"></a><span class="type"><a href="qstring.html">QString</a></span> QTextDocumentFragment::<span class="name">toHtml</span> ( const <span class="type"><a href="qbytearray.html">QByteArray</a></span> & <i>encoding</i> ) 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="qtextcodec.html">QTextCodec</a>.</p> <!-- @@@toHtml --> <!-- $$$toHtml$$$toHtml --> <h3 class="fn"><a name="toHtml-2"></a><span class="type"><a href="qstring.html">QString</a></span> QTextDocumentFragment::<span class="name">toHtml</span> () const</h3> <p>This is an overloaded function.</p> <!-- @@@toHtml --> <!-- $$$toPlainText[overload1]$$$toPlainText --> <h3 class="fn"><a name="toPlainText"></a><span class="type"><a href="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"><a name="operator-eq"></a><span class="type">QTextDocumentFragment</span> & QTextDocumentFragment::<span class="name">operator=</span> ( const <span class="type">QTextDocumentFragment</span> & <i>other</i> )</h3> <p>Assigns the <i>other</i> fragment to this fragment.</p> <!-- @@@operator= --> </div> </div> </div> </div> <div class="ft"> <span></span> </div> </div> <div class="footer"> <p> <acronym title="Copyright">©</acronym> 2013 Digia Plc and/or its subsidiaries. Documentation contributions included herein are the copyrights of their respective owners.</p> <br /> <p> 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.</p> <p> Documentation sources may be obtained from <a href="http://www.qt-project.org"> www.qt-project.org</a>.</p> <br /> <p> Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide. All other trademarks are property of their respective owners. <a title="Privacy Policy" href="http://en.gitorious.org/privacy_policy/">Privacy Policy</a></p> </div> <script src="scripts/functions.js" type="text/javascript"></script> </body> </html>