11int main(
int argc,
char *argv[])
13 QApplication app(argc, argv);
14 QTextEdit *editor =
new QTextEdit;
17 QTextDocument *document = editor->document();
18 QTextCursor redCursor(document);
20 QTextCursor blueCursor(document);
23 QTextCharFormat redFormat(redCursor.charFormat());
24 redFormat.setForeground(Qt::red);
25 QTextCharFormat blueFormat(blueCursor.charFormat());
26 blueFormat.setForeground(Qt::blue);
28 redCursor.setCharFormat(redFormat);
29 blueCursor.setCharFormat(blueFormat);
31 for (
int i = 0; i < 20; ++i) {
33 redCursor.insertText(tr(
"%1 ").arg(i), redFormat);
35 blueCursor.insertText(tr(
"%1 ").arg(i), blueFormat);
38 editor->setWindowTitle(tr(
"Text Document Cursors"));
39 editor->resize(320, 480);