How to Use QTextEdit: Difference between revisions

From Qt Wiki
Jump to navigation Jump to search
No edit summary
mNo edit summary
 
(5 intermediate revisions by 4 users not shown)
Line 1: Line 1:
{{LangSwitch}}
[[Category:HowTo]]
[[Category:HowTo]]
'''English''' [[How_to_Use_QTextEdit_German|Deutsch]]
[toc align_right="yes"]
= How to use QTextEdit =
== Overview ==
== Overview ==


With "QTextEdit":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.
With {{DocLink|QTextEdit}}, 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 ==
== Important methods ==


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


== Example ==
== Example ==
Line 22: Line 20:
QTextEdit can be used for multiple purposes, here is a simple editor:
QTextEdit can be used for multiple purposes, here is a simple editor:


<code><br />#include &lt;QApplication&amp;gt;<br />#include &lt;QTextEdit&amp;gt;
<code>
#include <QApplication>
#include <QTextEdit>


int main(int argc, char **argv)<br />{<br /> QApplication app(argc, argv);
int main(int argc, char **argv)
{
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;);
QTextEdit *txt = new QTextEdit();
txt->setText("Hello, world!");
txt->append("Appending some text…");


txt-&gt;show();<br /> return app.exec&amp;amp;#40;&amp;#41;;<br />}
txt->show();
return app.exec();
}
</code>

Latest revision as of 21:26, 27 June 2015

En Ar Bg De El Es Fa Fi Fr Hi Hu It Ja Kn Ko Ms Nl Pl Pt Ru Sq Th Tr Uk Zh

Overview

With QTextEdit, 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)

Resets the displayed text to the specified one.

void append(const QString text)

Appends the specified text to the displayed text.

QString toHtml()

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>
#include <QTextEdit>

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();
}