I create QTextTable and populate it with data.
Then I print out table via using QTextDocument.
I can print out table successfully. But in some pages cells are divided.
For example If my cell is three lines, first line of table is in bottom of 5. page, second and third lines of table are in top of 6. page.
How do I get rid of this problem?
I create QTextTable:
QTextTableCellFormat cellFormat;
cellFormat.setLeftPadding(7);
cellFormat.setRightPadding(7);
cellFormat.setTopPadding(2);
QBrush blackBrush
(Qt
::SolidPattern);
tableFormat.setAlignment(Qt::AlignLeft);
tableFormat.setBorderBrush(blackBrush);
tableFormat.setBorder(0.5);
tableFormat.setCellSpacing(0);
QTextTable *table
= cursor.
insertTable(100,
10,tableFormat
);
cell.setFormat(cellFormat);
cell.firstCursorPosition().insertText("this is long sentence");
....
TextDocument *document=new QTextDocument(this);
QTextCursor cursor(document);
cursor.movePosition(QTextCursor::Start);
QTextTableCellFormat cellFormat;
cellFormat.setLeftPadding(7);
cellFormat.setRightPadding(7);
cellFormat.setTopPadding(2);
QBrush blackBrush(Qt::SolidPattern);
QTextTableFormat tableFormat;
tableFormat.setAlignment(Qt::AlignLeft);
tableFormat.setBorderBrush(blackBrush);
tableFormat.setBorder(0.5);
tableFormat.setCellSpacing(0);
tableFormat.setBorderStyle(QTextFrameFormat::BorderStyle_Solid);
tableFormat.setWidth(QTextLength(QTextLength::PercentageLength, 100));
QTextTable *table = cursor.insertTable(100,10,tableFormat);
QTextTableCell cell=table->cellAt(1,0);
cell.setFormat(cellFormat);
cell.firstCursorPosition().insertText("this is long sentence");
....
To copy to clipboard, switch view to plain text mode
And I print out:
printer.
setOrientation(QPrinter::Landscape);
printer.
setPageMargins(10,
10,
10,
50,
QPrinter::Millimeter);
if (dlg
->exec
() != QDialog::Accepted) return;
document->print(&printer);
QPrinter printer;
printer.setOrientation(QPrinter::Landscape);
printer.setPageMargins(10,10,10,50,QPrinter::Millimeter);
QPrintDialog *dlg = new QPrintDialog(&printer, this);
if (dlg->exec() != QDialog::Accepted)
return;
document->print(&printer);
To copy to clipboard, switch view to plain text mode
sorry for my English
Bookmarks