Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
main.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
3#include <QApplication>
4#include <QTextEdit>
5
6QString tr(const char *text)
7{
9}
10
11int main(int argc, char *argv[])
12{
13 QApplication app(argc, argv);
14 QTextEdit *editor = new QTextEdit;
15
17 QTextDocument *document = editor->document();
18 QTextCursor redCursor(document);
20 QTextCursor blueCursor(document);
22
23 QTextCharFormat redFormat(redCursor.charFormat());
24 redFormat.setForeground(Qt::red);
25 QTextCharFormat blueFormat(blueCursor.charFormat());
26 blueFormat.setForeground(Qt::blue);
27
28 redCursor.setCharFormat(redFormat);
29 blueCursor.setCharFormat(blueFormat);
30
31 for (int i = 0; i < 20; ++i) {
32 if (i % 2 == 0)
33 redCursor.insertText(tr("%1 ").arg(i), redFormat);
34 if (i % 5 == 0)
35 blueCursor.insertText(tr("%1 ").arg(i), blueFormat);
36 }
37
38 editor->setWindowTitle(tr("Text Document Cursors"));
39 editor->resize(320, 480);
40 editor->show();
41 return app.exec();
42}
The QApplication class manages the GUI application's control flow and main settings.
static int exec()
Enters the main event loop and waits until exit() is called, then returns the value that was set to e...
static QString translate(const char *context, const char *key, const char *disambiguation=nullptr, int n=-1)
\threadsafe
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
\reentrant \inmodule QtGui
Definition qtextcursor.h:30
\reentrant \inmodule QtGui
The QTextEdit class provides a widget that is used to edit and display both plain and rich text.
Definition qtextedit.h:27
QTextDocument * document
the underlying document of the text editor.
Definition qtextedit.h:51
int main()
[0]
QString text
@ blue
Definition qnamespace.h:37
@ red
Definition qnamespace.h:35
SSL_CTX int void * arg
#define tr(X)
QApplication app(argc, argv)
[0]