Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-79696

The first block in a QTextEdit object does not display the top margin.

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P3: Somewhat important
    • None
    • 5.13.1
    • None
    • Linux/X11

    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;
      }
      

       

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            qt.team.quick.subscriptions Qt Quick and Widgets Team
            serious Frank Sembowski
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes