qt qprinter new page
-
ex) The picture when you go to the next page.
Ex) A picture that doesn't go to the next page
void QCustomReportForm::BtnPrint() { QPrinter printer(QPrinter::HighResolution); QPainter* painter = new QPainter(&printer); painter->begin(&printer); //printer.setPageSize(QPagedPaintDevice::A4); //printer.setFullPage(true); QRect rect = painter->viewport(); QPixmap buffer = m_pReportWidget->grab(); painter->drawPixmap(0, 0, buffer.scaled(rect.size(), Qt::KeepAspectRatio, Qt::SmoothTransformation)); painter->end(); } void QReportForm::CreateTable() { //QTextDocument textdoc; /*QString html = "<style>\ table{width=\"5000%\"; height=\"5000%\";}\ td{text-align: center;}</style>";*/ QString Header("<table border=1 align=center width=\"100%\">\ <tr bgcolor=#5368D6>\ <td align=center>1</td>\ <td align=center>2</td>\ <td align=center>3</td>\ <td align=center>4</td>\ <td align=center>5</td>\ <td align=center>6</td>\ <td align=center>7</td>\ <td align=center>8</td>\ <td align=center>9</td>\ <td align=center>10</td>\ </tr>"); QString data; for (int i = 0; i < 10; i++) { QString strTemp = QString("<tr>\ <td align=center>{data}</td>\ <td align=center>{data}</td>\ <td align=center>{data}</td>\ <td align=center>{data}</td>\ <td align=center>{data}</td>\ <td align=center>{data}</td>\ <td align=center>{data}</td>\ <td align=center>{data}</td>\ <td align=center>{data}</td>\ <td align=center>{data}</td>\ </tr>"); strTemp.replace("{data}", QString("%1").arg(i)); data.append(strTemp); } QString HeaderEnd("</table>"); //textdoc.setHtml(Header); this->ui.label_14->setTextFormat(Qt::RichText); this->ui.label_14->setText(Header+data+HeaderEnd); }
Is there a flag when the page goes over from the qprinter?
And I want to print it on the next page, but how can I print it? -
Hi
Im not really sure what the pictures should tell me :)Is there a flag when the page goes over from the qprinter?
No. not if you mean it will automatically tell you if you print more than can fit on one page.
This you must keep track of yourself.And I want to print it on the next page, but how can I print it?
call https://doc.qt.io/qt-5/qprinter.html#newPage
to get a new page to print/draw on. -
@IknowQT
Hi
We paint when we print so to speak.
You need to keep track of how much space of a page you used, and if it's full you must
call newPage and continue printing the rest there.Since you are printing a screengrab of widgets, in your case, you have to draw only a portion of the
image on first page and then the rest on the next page. -
Hi, out of curiosity: I see you commented out using QTextDocument with HTML content - was QTextDocument not handling your data properly?
Asking since from my experience QTextDocument handles paging much better and automatically than anything else and getting the print out is just one command.