QTextCursor cursor = textEdit->textCursor(); // Get current cursor position QTextCharFormat charFormat = cursor.charFormat(); // Get current character format charFormat.setFontPointSize(14); // Set font size to 14 charFormat.setForeground(QColor(Qt::red)); // Set font color to red cursor.setCharFormat(charFormat); // Apply the updated character format
QTextCursor cursor = textEdit->textCursor(); // Get current cursor position QTextBlockFormat blockFormat = cursor.blockFormat(); // Get current block format blockFormat.setAlignment(Qt::AlignCenter); // Set text alignment to center cursor.setBlockFormat(blockFormat); // Apply the updated block formatThis example shows how to set the text alignment of the current paragraph to center in a QTextEdit widget. Package library: Qt.