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

QTextDocument::print: Page break after a table messes up the printed output

    XMLWordPrintable

Details

    Description

      QTextDocument::print: Page break after a table messes up the printed output.

      Test case main.cpp to reproduce
      =======================================
      // Testcase for QTextDocument::print
      #include <QtGui>

      static void addTable(QTextCursor& cursor)
      {
      const int columns = 4;
      const int rows = 1;

      QTextTableFormat tableFormat;
      //tableFormat.setHeaderRowCount( 1 );
      QTextTable* textTable = cursor.insertTable( rows + 1,columns,tableFormat );
      QTextCharFormat tableHeaderFormat;
      tableHeaderFormat.setBackground( QColor( "#DADADA" ) );

      QStringList headers;
      headers << "Product" << "Reference" << "Price" << "Price with shipping";

      for( int column = 0; column < columns; column++ )

      { QTextTableCell cell = textTable->cellAt( 0, column ); Q_ASSERT( cell.isValid() ); cell.setFormat( tableHeaderFormat ); QTextCursor cellCursor = cell.firstCursorPosition(); cellCursor.insertText( headers[column] ); }

      int row = 0;
      for( int column = 0; column < columns; column++ )

      { QTextTableCell cell = textTable->cellAt( row + 1, column ); Q_ASSERT( cell.isValid() ); QTextCursor cellCursor = cell.firstCursorPosition(); const QString cellText = QString( "A 220.00" ); cellCursor.insertText( cellText ); }

      }

      int main(int argc, char *argv[])
      {
      QApplication app(argc, argv);

      QTextDocument textDocument;
      QTextCursor cursor(&textDocument);
      cursor.insertText("This is the first page");

      addTable(cursor);

      QTextBlockFormat blockFormat;
      blockFormat.setPageBreakPolicy(QTextFormat::PageBreak_AlwaysBefore);
      cursor.insertBlock(blockFormat);
      cursor.insertText("This is the second page");

      QTextEdit edit;
      edit.setDocument(&textDocument);
      edit.show();

      QPrinter printer;
      printer.setOutputFileName("test.pdf");
      printer.setFullPage(true);

      textDocument.print(&printer);

      return app.exec();
      }

      Attachments

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

        Activity

          People

            rodal Samuel Rødal
            admin Administrator
            Votes:
            2 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes