cell division problem on QTextDocument
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:
Code:
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");
....
And I print out:
Code:
printer.
setOrientation(QPrinter::Landscape);
printer.
setPageMargins(10,
10,
10,
50,
QPrinter::Millimeter);
if (dlg
->exec
() != QDialog::Accepted) return;
document->print(&printer);
sorry for my English
Re: cell division problem on QTextDocument
I found a solution for my problem in stackoverflow.com
I created table using HTML but I noticed that "page-break-inside" is not supported by Qt.
Is there a way to use it?
Code:
css="<style type=\"text/css\">";
css+="table { page-break-inside:auto; border-style:solid;border-width: 1px }";
css+="tr { page-break-inside:avoid; page-break-after:auto}";
css+="thead { display:table-header-group }";
css+="tfoot { display:table-footer-group }";
css+="</style>";
yazi="<table><thead><tr><th>header</th></tr></thead><tbody>";
yazi.append("<tr><td>");
for(int i=0;i<ui->table->rowCount()-1;i++)
{
yazi.
append("<tr><td>"+QString::number(i
+1)+"</td>");
for(int j=0;j<ui->table->columnCount();j++)
{
yazi.append("<td width=\"10%\">"+ui->table->item(i,j)->text()+"</td>");
}
yazi.append("</tr>");
}
yazi.append("</tbody><tfoot><tr><td>footer</td></tr></tfoot></table>");
printer.
setOrientation(QPrinter::Landscape);
printer.
setPageMargins(10,
10,
10,
10,
QPrinter::Millimeter);
document->setHtml(css+yazi);
if (dlg
->exec
() != QDialog::Accepted) return;
document->print(&printer);