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
QTextCursor cursor(editor->textCursor());
17
cursor.movePosition(QTextCursor::Start);
18
19
QTextCharFormat plainFormat(cursor.charFormat());
20
21
QTextCharFormat headingFormat = plainFormat;
22
headingFormat.setFontWeight(QFont::Bold);
23
headingFormat.setFontPointSize(16);
24
25
QTextCharFormat emphasisFormat = plainFormat;
26
emphasisFormat.setFontItalic(
true
);
27
28
QTextCharFormat qtFormat = plainFormat;
29
qtFormat.setForeground(QColor(
"#990000"
));
30
31
QTextCharFormat underlineFormat = plainFormat;
32
underlineFormat.setFontUnderline(
true
);
33
34
//! [0]
35
cursor.insertText(tr(
"Character formats"
),
36
headingFormat);
37
38
cursor.insertBlock();
39
40
cursor.insertText(tr(
"Text can be displayed in a variety of "
41
"different character formats. "
), plainFormat);
42
cursor.insertText(tr(
"We can emphasize text by "
));
43
cursor.insertText(tr(
"making it italic"
), emphasisFormat);
44
//! [0]
45
cursor.insertText(tr(
", give it a "
), plainFormat);
46
cursor.insertText(tr(
"different color "
), qtFormat);
47
cursor.insertText(tr(
"to the default text color, "
), plainFormat);
48
cursor.insertText(tr(
"underline it"
), underlineFormat);
49
cursor.insertText(tr(
", and use many other effects."
), plainFormat);
50
51
editor->setWindowTitle(tr(
"Text Document Character Formats"
));
52
editor->resize(320, 480);
53
editor->show();
54
return
app.exec();
55
}
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-charformats
main.cpp
Generated on
for Qt by
1.18.0