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 QTextCursor cursor(editor->textCursor());
17 cursor.movePosition(QTextCursor::Start);
18
19 QTextCharFormat plainFormat(cursor.charFormat());
20 QTextCharFormat colorFormat = plainFormat;
21 colorFormat.setForeground(Qt::red);
22
23 cursor.insertText(tr("Text can be displayed in a variety of "
24 "different character "
25 "formats. "), plainFormat);
26 cursor.insertText(tr("We can emphasize text by making it "));
27 cursor.insertText(tr("italic, give it a different color "));
28 cursor.insertText(tr("to the default text color, underline it, "));
29 cursor.insertText(tr("and use many other effects."));
30
31 QString searchString = tr("text");
32
33 QTextDocument *document = editor->document();
34//! [0]
35 QTextCursor newCursor(document);
36
37 while (!newCursor.isNull() && !newCursor.atEnd()) {
38 newCursor = document->find(searchString, newCursor);
39
40 if (!newCursor.isNull()) {
41 newCursor.movePosition(QTextCursor::WordRight,
42 QTextCursor::KeepAnchor);
43
44 newCursor.mergeCharFormat(colorFormat);
45 }
46//! [0] //! [1]
47 }
48//! [1]
49
50 editor->setWindowTitle(tr("Text Document Find"));
51 editor->resize(320, 480);
52 editor->show();
53 return app.exec();
54}
int main(int argc, char *argv[])
[ctor_close]
QString tr(const char *)