Results 1 to 3 of 3

Thread: QTextEdit printing margin problem

  1. #1
    Join Date
    Sep 2013
    Posts
    2
    Qt products
    Qt5
    Platforms
    Windows

    Default QTextEdit printing margin problem

    As can be seen in the attached picture drawn in QTextEdit print from the table too much going on margins. And these gaps can not be changed.
    I'm sorry for bad english, translation, google translate
    code:
    {
    //QTextEdit add table:

    QVector<QTextLength> columnWidth;
    columnWidth.append (QTextLength(QTextLength::FixedLength, 15));
    columnWidth.append (QTextLength(QTextLength::FixedLength, 20));
    columnWidth.append (QTextLength(QTextLength::FixedLength, 100));
    columnWidth.append (QTextLength(QTextLength::FixedLength, 80));
    columnWidth.append (QTextLength(QTextLength::FixedLength, 70));
    columnWidth.append (QTextLength(QTextLength::FixedLength, 80));
    columnWidth.append (QTextLength(QTextLength::FixedLength, 70));
    columnWidth.append (QTextLength(QTextLength::FixedLength, 30));
    columnWidth.append (QTextLength(QTextLength::FixedLength, 30));
    columnWidth.append (QTextLength(QTextLength::FixedLength, 30));
    columnWidth.append (QTextLength(QTextLength::FixedLength, 30));
    columnWidth.append (QTextLength(QTextLength::FixedLength, 40));
    columnWidth.append (QTextLength(QTextLength::FixedLength, 30));
    columnWidth.append (QTextLength(QTextLength::FixedLength, 50));
    columnWidth.append (QTextLength(QTextLength::FixedLength, 50));
    columnWidth.append (QTextLength(QTextLength::FixedLength, 50));
    columnWidth.append (QTextLength(QTextLength::FixedLength, 50));
    columnWidth.append (QTextLength(QTextLength::FixedLength, 150));
    columnWidth.append (QTextLength(QTextLength::FixedLength, 40));

    //QTextCursor cursor(ui->textBrowser->textCursor ());
    QTextCursor cursor1(ui->textEdit->textCursor ());

    cursor.movePosition(QTextCursor::Start);


    QTextTableCellFormat cellFormat;
    cellFormat.setLeftPadding(7);
    cellFormat.setRightPadding(7);
    QBrush blackBrush(Qt::SolidPattern);
    QTextTableFormat tableFormat;
    tableFormat.setAlignment(Qt::AlignLeft);
    tableFormat.setBorderBrush(blackBrush);
    tableFormat.setBorder(.5);
    tableFormat.setCellSpacing(0);
    tableFormat.setBorderStyle(QTextFrameFormat::Borde rStyle_Solid);
    tableFormat.setWidth(QTextLength(QTextLength::Perc entageLength, 50));
    tableFormat.setColumnWidthConstraints (columnWidth);

    //QTextTable *table = cursor.insertTable (100,19, tableFormat);
    QTextTable *table1 = cursor1.insertTable (100,19, tableFormat);
    table->mergeCells (1,0,10,1);

    QTextBlockFormat centerAlignment;
    centerAlignment.setAlignment(Qt::AlignHCenter);
    centerAlignment.setTextIndent (QTextOption::WordWrap);

    cursor = table->cellAt(0, 0).firstCursorPosition();
    cursor.setBlockFormat(centerAlignment);
    cursor.insertText("Hello, this is my first post here!");
    }

    void MainWindow::_printButton()
    {
    #ifndef QT_NO_PRINTER
    QPrinter printer(QPrinter::HighResolution);
    printer.setPaperSize (QPrinter::A4);
    printer.setOrientation (QPrinter::Landscape);
    printer.setPageMargins(5,5,5,5,QPrinter::Millimete r);
    printer.setResolution(1200);
    printer.setFullPage(true);
    QPrintPreviewDialog preview(&printer, this);

    preview.setWindowFlags ( Qt::Window );

    connect(&preview, SIGNAL(paintRequested(QPrinter *)),SLOT(printPreview(QPrinter *)));
    preview.exec();
    #endif
    }

    void MainWindow::_printPreview (QPrinter *printer)
    {
    ui->textEdit->document ()->documentLayout()->setPaintDevice(printer);
    ui->textEdit->document ()->setPageSize(QSizeF(printer->paperRect ().size ()));
    ui->textBrowser->document ()->print (printer);
    }

    Adsız.jpg

  2. #2
    Join Date
    Dec 2012
    Posts
    197
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    25
    Thanked 41 Times in 33 Posts

    Default Re: QTextEdit printing margin problem

    A great start would be reading the forum rules one of which is :
    Use code tags for better reading, understanding, and viewing of code.
    Last edited by toufic.dbouk; 29th September 2013 at 11:32.

  3. #3
    Join Date
    Sep 2013
    Posts
    2
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QTextEdit printing margin problem

    Thanks, that would take care of it.

Similar Threads

  1. QTextEdit bottom margin
    By ad3d in forum Newbie
    Replies: 3
    Last Post: 22nd August 2011, 08:52
  2. QTextedit Printing
    By acdc in forum Qt Programming
    Replies: 0
    Last Post: 25th March 2010, 18:34
  3. Replies: 3
    Last Post: 5th February 2009, 15:32
  4. Change margin on QTextEdit print()
    By Dii in forum Qt Programming
    Replies: 2
    Last Post: 20th May 2008, 22:45
  5. Printing with QTextEdit
    By vermarajeev in forum Qt Programming
    Replies: 2
    Last Post: 14th November 2007, 12:47

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.