Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
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{
8 return QApplication::translate(text, text);
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
19 QImage image(64, 64, QImage::Format_RGB32);
20 image.fill(qRgb(255, 160, 128));
21
22//! [Adding a resource]
23 document->addResource(QTextDocument::ImageResource,
24 QUrl("mydata://image.png"), QVariant(image));
25//! [Adding a resource]
26
27//! [Inserting an image with a cursor]
28 QTextImageFormat imageFormat;
29 imageFormat.setName("mydata://image.png");
30 cursor.insertImage(imageFormat);
31//! [Inserting an image with a cursor]
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
41//! [Inserting an image using HTML]
42 editor->append("<img src=\"mydata://image.png\" />");
43//! [Inserting an image using HTML]
44
45 return app.exec();
46}
int main(int argc, char *argv[])
[ctor_close]
QString tr(const char *)