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
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}
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...
The QColor class provides colors based on RGB, HSV or CMYK values.
Definition qcolor.h:31
static QString translate(const char *context, const char *key, const char *disambiguation=nullptr, int n=-1)
\threadsafe
@ Bold
Definition qfont.h:70
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
void setFontUnderline(bool underline)
If underline is true, sets the text format's font to be underlined; otherwise it is displayed non-und...
void setFontItalic(bool italic)
If italic is true, sets the text format's font to be italic; otherwise the font will be non-italic.
void setFontWeight(int weight)
Sets the text format's font weight to weight.
\reentrant \inmodule QtGui
Definition qtextcursor.h:30
The QTextEdit class provides a widget that is used to edit and display both plain and rich text.
Definition qtextedit.h:27
QTextCursor textCursor() const
Returns a copy of the QTextCursor that represents the currently visible cursor.
void setForeground(const QBrush &brush)
Sets the foreground brush to the specified brush.
int main()
[0]
QString text
QCursor cursor
#define tr(X)
QApplication app(argc, argv)
[0]