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 <QTextBlock>
5#include <QTextEdit>
6
7QString tr(const char *text)
8{
9 return QApplication::translate(text, text);
10}
11
12int main(int argc, char *argv[])
13{
14 QApplication app(argc, argv);
15 QTextEdit *editor = new QTextEdit;
16
17 QTextDocument *document = new QTextDocument(editor);
18 QTextCursor cursor(document);
19
20 QTextImageFormat imageFormat;
21 imageFormat.setName(":/images/advert.png");
22 cursor.insertImage(imageFormat);
23
24 QTextBlock block = cursor.block();
25 QTextFragment fragment;
26 QTextBlock::iterator it;
27
28 for (it = block.begin(); !(it.atEnd()); ++it) {
29 fragment = it.fragment();
30
31 if (fragment.contains(cursor.position()))
32 break;
33 }
34
35//! [0]
36 if (fragment.isValid()) {
37 QTextImageFormat newImageFormat = fragment.charFormat().toImageFormat();
38
39 if (newImageFormat.isValid()) {
40 newImageFormat.setName(":/images/newimage.png");
41 QTextCursor helper = cursor;
42
43 helper.setPosition(fragment.position());
44 helper.setPosition(fragment.position() + fragment.length(),
45 QTextCursor::KeepAnchor);
46 helper.setCharFormat(newImageFormat);
47//! [0] //! [1]
48 }
49//! [1] //! [2]
50 }
51//! [2]
52
53 cursor.insertBlock();
54 cursor.insertText("Code less. Create more.");
55
56 editor->setDocument(document);
57 editor->setWindowTitle(tr("Text Document Image Format"));
58 editor->resize(320, 480);
59 editor->show();
60
61 return app.exec();
62}
int main(int argc, char *argv[])
[ctor_close]
QString tr(const char *)