I wanted to increase spacing between paragraphs (text blocks) in QPlainTextEdit, to no avail. After experimenting I found that though some format properties (e.g., background color) take effect, others (e.g., margins) are ignored.
I found this bug report, but it mentions only QTextBlockFormat::lineHeight()
. In my case, almost all methods of QTextBlockFormat::*
are ignored. A minimal example:
#include <QtWidgets>
int main(int argc, char *argv[]) {
QApplication a(argc, argv);
QPlainTextEdit te;
te.setPlainText("block1\nblock2\nblock3");
QTextCursor cursor = te.textCursor();
cursor.select(QTextCursor::Document);
QTextBlockFormat fmt;
fmt.setBackground(QColor(Qt::yellow));
fmt.setBottomMargin(600);
fmt.setIndent(20);
fmt.setTopMargin(600);
fmt.setLeftMargin(40);
cursor.setBlockFormat(fmt);
te.show();
return a.exec();
}
Except fmt.setBackground(QColor(Qt::yellow))
, others are all ignored. Using Qt 5.10.