summaryrefslogtreecommitdiffstats
path: root/src/gui/doc/snippets/code/doc_src_richtext.cpp
blob: 8d7e76503a0771ae5ff9fd4f54f82a2355df71db (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
#include <QTextDocument>
#include <QTextEdit>

namespace doc_src_richtext {

void wrapper() {
//! [0]
QTextDocument *newDocument = new QTextDocument;
//! [0]


//! [1]
QTextEdit *editor = new QTextEdit;
QTextDocument *editorDocument = editor->document();
//! [1]
Q_UNUSED(newDocument);
Q_UNUSED(editorDocument);
} // wrapper

void wrapper2() {
auto parent = new QTextEdit();
QString aStringContainingHTMLtext;
//! [2]
QTextEdit *editor = new QTextEdit(parent);
editor->setHtml(aStringContainingHTMLtext);
editor->show();
//! [2]


//! [3]
QTextDocument *document = editor->document();
//! [3]
Q_UNUSED(document);

//! [4]
QTextCursor cursor = editor->textCursor();
//! [4]


//! [5]
editor->setTextCursor(cursor);
//! [5]


QTextEdit textEdit;
QTextCursor textCursor;
QString paragraphText;
//! [6]
textEdit.show();

textCursor.beginEditBlock();

for (int i = 0; i < 1000; ++i) {
    textCursor.insertBlock();
    textCursor.insertText(paragraphText.at(i));
}

textCursor.endEditBlock();
//! [6]

} // wrapper2
} // doc_src_richtext