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
(Cleanup)
mNo edit summary
 
Line 7: Line 7:
== Important methods ==
== Important methods ==


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



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