QTextDocument doc; QTextCursor cursor(&doc); cursor.insertText("Hello World!"); cursor.insertBlock(); cursor.insertText("This is a new paragraph.");
QTextBlockFormat blockFormat; blockFormat.setAlignment(Qt::AlignCenter); QTextDocument doc; QTextCursor cursor(&doc); cursor.insertText("This text is centered", blockFormat);This example sets the alignment of a QTextBlock using the QTextBlockFormat class. A new QTextDocument and QTextCursor object are created, and the insertText() function is called with the text and the formatting object. Package Library: Qt Library.