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
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
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);
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
}
QApplication
The QApplication class manages the GUI application's control flow and main settings.
Definition
qapplication.h:32
QApplication::exec
static int exec()
Enters the main event loop and waits until exit() is called, then returns the value that was set to e...
Definition
qapplication.cpp:2560
QColor
The QColor class provides colors based on RGB, HSV or CMYK values.
Definition
qcolor.h:31
QCoreApplication::translate
static QString translate(const char *context, const char *key, const char *disambiguation=nullptr, int n=-1)
\threadsafe
Definition
qcoreapplication.cpp:2357
QFont::Bold
@ Bold
Definition
qfont.h:70
QString
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition
qstring.h:129
QTextCharFormat
\reentrant
Definition
qtextformat.h:383
QTextCharFormat::setFontUnderline
void setFontUnderline(bool underline)
If underline is true, sets the text format's font to be underlined; otherwise it is displayed non-und...
Definition
qtextformat.h:473
QTextCharFormat::setFontItalic
void setFontItalic(bool italic)
If italic is true, sets the text format's font to be italic; otherwise the font will be non-italic.
Definition
qtextformat.h:452
QTextCharFormat::setFontWeight
void setFontWeight(int weight)
Sets the text format's font weight to weight.
Definition
qtextformat.h:448
QTextCursor
\reentrant \inmodule QtGui
Definition
qtextcursor.h:30
QTextCursor::Start
@ Start
Definition
qtextcursor.h:64
QTextEdit
The QTextEdit class provides a widget that is used to edit and display both plain and rich text.
Definition
qtextedit.h:27
QTextEdit::textCursor
QTextCursor textCursor() const
Returns a copy of the QTextCursor that represents the currently visible cursor.
Definition
qtextedit.cpp:851
QTextFormat::setForeground
void setForeground(const QBrush &brush)
Sets the foreground brush to the specified brush.
Definition
qtextformat.h:358
main
int main()
[0]
Definition
doc_src_objecttrees.cpp:5
text
QString text
Definition
doc_src_properties.cpp:105
cursor
QCursor cursor
Definition
doc_src_properties.cpp:25
tr
#define tr(X)
Definition
qtemporaryfile.cpp:21
app
QApplication app(argc, argv)
[0]
qtbase
src
gui
doc
snippets
textdocument-charformats
main.cpp
Generated by
1.10.0