Qt wiki will be updated on October 12th 2023 starting at 11:30 AM (EEST) and the maintenance will last around 2-3 hours. During the maintenance the site will be unavailable.

How to Use QTextEdit: Difference between revisions

From Qt Wiki
Jump to navigation Jump to search
No edit summary
 
No edit summary
Line 1: Line 1:
'''English''' [[How to Use QTextEdit German|Deutsch]]
[[Category:HowTo]]


=How to use QTextEdit=
'''English''' [[How_to_Use_QTextEdit_German|Deutsch]]


==Overview==
[toc align_right="yes"]


With [http://doc.qt.io/qt-5.0/qtwidgets/qtextedit.html QTextEdit] ''[qt.io]'', you get an easy to use class to create a rich text field. With this text field, you can display plain text, but also rich text like <span class="caps">HTML</span>-formatted text and images.
= How to use QTextEdit =


==Important methods==
== Overview ==


<span class="caps">HTML</span>
With &quot;QTextEdit&amp;quot;:http://doc.qt.io/qt-5.0/qtwidgets/qtextedit.html, you get an easy to use class to create a rich text field. With this text field, you can display plain text, but also rich text like HTML-formatted text and images.


==Example==
== Important methods ==
 
* <code>void setText(const QString text)<code><br />Resets the displayed text to the specified one.
* </code>void append(const QString text)</code><br />Appends the specified text to the displayed text.
* <code>QString toHtml()<code><br />Returns the content of the QTextEdit text field as HTML-formatted text.
* </code>QString toPlainText()</code><br />Returns the content of the QTextEdit text field as plain text.
 
== Example ==


QTextEdit can be used for multiple purposes, here is a simple editor:
QTextEdit can be used for multiple purposes, here is a simple editor:


===Categories:===
<code><br />#include &lt;QApplication&amp;gt;<br />#include &lt;QTextEdit&amp;gt;
 
int main(int argc, char **argv)<br />{<br /> QApplication app(argc, argv);
 
QTextEdit *txt = new QTextEdit();<br /> txt-&gt;setText(&quot;Hello, world!&quot;);<br /> txt-&gt;append(&quot;Appending some text…&quot;);


* [[:Category:HowTo|HowTo]]
txt-&gt;show();<br /> return app.exec&amp;amp;#40;&amp;#41;;<br />}

Revision as of 14:27, 23 February 2015


English Deutsch

[toc align_right="yes&quot;]

How to use QTextEdit

Overview

With "QTextEdit&quot;:http://doc.qt.io/qt-5.0/qtwidgets/qtextedit.html, you get an easy to use class to create a rich text field. With this text field, you can display plain text, but also rich text like HTML-formatted text and images.

Important methods

  • void setText(const QString text)<code><br />Resets the displayed text to the specified one.
    *
    
    void append(const QString text)
    Appends the specified text to the displayed text.
  • QString toHtml()<code><br />Returns the content of the QTextEdit text field as HTML-formatted text.
    *
    
    QString toPlainText()
    Returns the content of the QTextEdit text field as plain text.

Example

QTextEdit can be used for multiple purposes, here is a simple editor:


#include <QApplication&gt;
#include <QTextEdit&gt;

int main(int argc, char **argv)
{
QApplication app(argc, argv);

QTextEdit *txt = new QTextEdit();
txt->setText("Hello, world!");
txt->append("Appending some text…");

txt->show();
return app.exec&amp;#40;&#41;;
}