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 QTextDocument *document = new QTextDocument(editor);
17 QTextCursor cursor(document);
18
20 image.fill(qRgb(255, 160, 128));
21
23 document->addResource(QTextDocument::ImageResource,
24 QUrl("mydata://image.png"), QVariant(image));
26
28 QTextImageFormat imageFormat;
29 imageFormat.setName("mydata://image.png");
30 cursor.insertImage(imageFormat);
32
33 cursor.insertBlock();
34 cursor.insertText("Code less. Create more.");
35
36 editor->setDocument(document);
37 editor->setWindowTitle(tr("Text Document Images"));
38 editor->resize(320, 480);
39 editor->show();
40
42 editor->append("<img src=\"mydata://image.png\" />");
44
45 return app.exec();
46}
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
\inmodule QtGui
Definition qimage.h:37
@ Format_RGB32
Definition qimage.h:46
\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
void append(const QString &text)
Appends a new paragraph with text to the end of the text edit.
void setDocument(QTextDocument *document)
void setName(const QString &name)
Sets the name of the image.
\inmodule QtCore
Definition qurl.h:94
\inmodule QtCore
Definition qvariant.h:65
int main()
[0]
QString text
QCursor cursor
Definition image.cpp:4
constexpr QRgb qRgb(int r, int g, int b)
Definition qrgb.h:30
#define tr(X)
QApplication app(argc, argv)
[0]