13 QApplication app(argc, argv);
16 QTextEdit *editor =
new QTextEdit();
17 QTextCursor cursor(editor->textCursor());
19 cursor.movePosition(QTextCursor::Start);
21 QTextBlockFormat blockFormat = cursor.blockFormat();
22 blockFormat.setTopMargin(4);
23 blockFormat.setLeftMargin(4);
24 blockFormat.setRightMargin(4);
25 blockFormat.setBottomMargin(4);
27 cursor.setBlockFormat(blockFormat);
28 cursor.insertText(tr(
"This contains plain text inside a "
29 "text block with margins to keep it separate "
30 "from other parts of the document."));
35 QTextBlockFormat backgroundFormat = blockFormat;
36 backgroundFormat.setBackground(QColor(
"lightGray"));
38 cursor.setBlockFormat(backgroundFormat);
40 cursor.insertText(tr(
"The background color of a text block can be "
41 "changed to highlight text."));
45 QTextBlockFormat rightAlignedFormat = blockFormat;
46 rightAlignedFormat.setAlignment(Qt::AlignRight);
48 cursor.setBlockFormat(rightAlignedFormat);
49 cursor.insertText(tr(
"The alignment of the text within a block is "
50 "controlled by the alignment properties of "
51 "the block itself. This text block is "
56 QTextBlockFormat paragraphFormat = blockFormat;
57 paragraphFormat.setAlignment(Qt::AlignJustify);
58 paragraphFormat.setTextIndent(32);
60 cursor.setBlockFormat(paragraphFormat);
61 cursor.insertText(tr(
"Text can be formatted so that the first "
62 "line in a paragraph has its own margin. "
63 "This makes the text more readable."));
67 QTextBlockFormat reverseFormat = blockFormat;
68 reverseFormat.setAlignment(Qt::AlignJustify);
69 reverseFormat.setTextIndent(32);
71 cursor.setBlockFormat(reverseFormat);
72 cursor.insertText(tr(
"The direction of the text can be reversed. "
73 "This is useful for right-to-left "
76 editor->setWindowTitle(tr(
"Text Block Formats"));
77 editor->resize(480, 480);