QPlainTextEdit文本对齐

时间:2017-02-28 13:36:51

标签: qt

以下代码适用于QTextEdit,但它不适用于QPlainTextEdit:

ui->setupUi(this);
ui->plainTextEdit->clear();
ui->plainTextEdit->appendPlainText("example");
ui->plainTextEdit->appendPlainText("example");
QTextCursor cursor = ui->plainTextEdit->textCursor();
QTextBlockFormat textBlockFormat = cursor.blockFormat();
textBlockFormat.setAlignment(Qt::AlignRight);
cursor.mergeBlockFormat(textBlockFormat);
ui->plainTextEdit->setTextCursor(cursor);

ui->plainTextEdit->appendPlainText("example");

cursor = ui->plainTextEdit->textCursor();
textBlockFormat = cursor.blockFormat();
textBlockFormat.setAlignment(Qt::AlignCenter);
cursor.mergeBlockFormat(textBlockFormat);
ui->plainTextEdit->setTextCursor(cursor);

我希望附加文本的对齐方式能够改变,但事实并非如此。

0 个答案:

没有答案