Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
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
6
QString
tr
(
const
char
*text)
7
{
8
return
QApplication::translate(text, text);
9
}
10
11
int
main
(
int
argc,
char
*argv[])
12
{
13
QApplication app(argc, argv);
14
QTextEdit *editor =
new
QTextEdit;
15
16
//! [0]
17
QTextDocument *document = editor->document();
18
QTextCursor redCursor(document);
19
//! [0] //! [1]
20
QTextCursor blueCursor(document);
21
//! [1]
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
}
main
int main(int argc, char *argv[])
[ctor_close]
Definition
src_corelib_animation_qpropertyanimation.cpp:100
tr
QString tr(const char *)
Definition
src_corelib_global_qglobal_widgets.cpp:67
qtbase
src
gui
doc
snippets
textdocument-cursors
main.cpp
Generated on
for Qt by
1.18.0