How to Use QTextEdit: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
Line 3: | Line 3: | ||
'''English''' [[How_to_Use_QTextEdit_German|Deutsch]] | '''English''' [[How_to_Use_QTextEdit_German|Deutsch]] | ||
[toc align_right= | [toc align_right="yes"] | ||
= How to use QTextEdit = | = How to use QTextEdit = | ||
Line 9: | Line 9: | ||
== Overview == | == Overview == | ||
With | 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. | ||
== Important methods == | == Important methods == | ||
* <code>void setText(const QString text)<code> | * <code>void setText(const QString text)<code> | ||
* </code>void append(const QString text)</code> | Resets the displayed text to the specified one. | ||
* <code>QString toHtml()<code> | * </code>void append(const QString text)</code> | ||
* </code>QString toPlainText()</code> | 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 26: | ||
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> | <code> | ||
#include <QApplication> | |||
#include <QTextEdit> | |||
int main(int argc, char **argv) | int main(int argc, char **argv) | ||
{ | |||
QApplication app(argc, argv); | |||
QTextEdit *txt = new QTextEdit(); | QTextEdit *txt = new QTextEdit(); | ||
txt->setText("Hello, world!"); | |||
txt->append("Appending some text…"); | |||
txt- | txt->show(); | ||
return app.exec(); | |||
} |
Revision as of 08:51, 25 February 2015
English Deutsch
[toc align_right="yes"]
How to use QTextEdit
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.
Important methods
- void append(const QString text)
void setText(const QString text)<code> Resets the displayed text to the specified one. *
Appends the specified text to the displayed text.
- QString toPlainText()
QString toHtml()<code> Returns the content of the QTextEdit text field as HTML-formatted text. *
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();
}