How to Use QTextEdit: Difference between revisions

From Qt Wiki
Jump to navigation Jump to search
(Add "cleanup" tag)
(Convert ExpressionEngine links)
Line 11: Line 11:
== 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 [http://doc.qt.io/qt-5.0/qtwidgets/qtextedit.html 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 ==

Revision as of 08:44, 4 March 2015

This article may require cleanup to meet the Qt Wiki's quality standards. Reason: Auto-imported from ExpressionEngine.
Please improve this article if you can. Remove the {{cleanup}} tag and add this page to Updated pages list after it's clean.

English Deutsch

[toc align_right="yes"]

How to use QTextEdit

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)<code>
    Resets the displayed text to the specified one.
    *
    
    void append(const QString text)

Appends the specified text to the displayed text.

  • QString toHtml()<code>
    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:

  1. include <QApplication>
  2. 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();

}