eemxas
28th September 2013, 21:58
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);
}
9644
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);
}
9644