English Deutsch

How to use QTextEdit

Overview

With QTextEdit [qt-project.org], 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.

Example

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

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

Categories: