The wiki is in the process of moving to Please make your edits there.

How_to_Use_QTextEdit | Qt Wiki | Qt Project

English Deutsch

How to use QTextEdit


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

    1. void setText(const QString text)

    Resets the displayed text to the specified one.
    1. void append(const QString text)

    Appends the specified text to the displayed text.
    1. QString toHtml()

    Returns the content of the QTextEdit text field as HTML-formatted text.
    1. QString toPlainText()

    Returns the content of the QTextEdit text field as plain text.


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

  1. #include <QApplication>
  2. #include <QTextEdit>
  4. int main(int argc, char **argv)
  5. {
  6.     QApplication app(argc, argv);
  8.     QTextEdit *txt = new QTextEdit();
  9.     txt->setText("Hello, world!\n");
  10.     txt->append("Appending some text...");
  12.     txt->show();
  13.     return app.exec();
  14. }