Details
-
Bug
-
Resolution: Unresolved
-
P3: Somewhat important
-
None
-
5.13.1
-
None
Description
setTopMargin() of QTextBlockFormat has no effect if it is applied to the first block of a QTextEdit object. But if a new block is inserted above the first block, the top margin of the original block (now second block) is applied.
This is particularly irritating because the first block is usually the title with a clear top margin.
#include "MainWindow.h" #include "ui_mainwindow.h" #include <QHBoxLayout> #include <QTextEdit> MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow), m_TextEdit(new QTextEdit(this)) { ui->setupUi(this); QHBoxLayout *layout = new QHBoxLayout(ui->centralwidget); layout->addWidget(m_TextEdit, 1, Qt::AlignHCenter); QTextCursor cursor(m_TextEdit->document()); QTextBlockFormat blockFormat; blockFormat.setTopMargin(30.0); blockFormat.setBottomMargin(30.0); cursor.insertText("First block of text."); // Write in first (default) block. cursor.insertBlock(); cursor.insertText("Second block of text."); cursor.insertBlock(); cursor.insertText("Third block of text."); cursor.select(QTextCursor::Document); cursor.setBlockFormat(blockFormat); // => First block lacks the top margin. } MainWindow::~MainWindow() { delete ui; delete m_TextEdit; }