How do you add Header/Footer in QTextDocument
-
Out of the box it gives me a table with page number at bottom:
void QueryResultView::printTable() { int row = table->model()->rowCount(); int column = table->model()->columnCount(); QPrinter printer; printer.setPageSize(QPageSize::A4); printer.setOutputFormat(QPrinter::PdfFormat); printer.setOutputFileName("test.pdf"); QTextDocument doc; QTextCursor cursor(&doc); QTextTableFormat tableFormat; tableFormat.setBorderCollapse(true); tableFormat.setHeaderRowCount(row); cursor.insertTable(row, column); for (int r = 0; r < row; r++) { for (int c = 0; c < column; c++) { auto index = table->model()->index(r, c); cursor.insertText( table->model()->data(index).toString() ); cursor.movePosition(QTextCursor::NextCell); } } doc.print(&printer); }
How to add page header/footer as well as table column header on each page?
-
I found this example interesting: https://github.com/jeromecc/qprintereasy
best regards
HoM -
Out of the box it gives me a table with page number at bottom:
void QueryResultView::printTable() { int row = table->model()->rowCount(); int column = table->model()->columnCount(); QPrinter printer; printer.setPageSize(QPageSize::A4); printer.setOutputFormat(QPrinter::PdfFormat); printer.setOutputFileName("test.pdf"); QTextDocument doc; QTextCursor cursor(&doc); QTextTableFormat tableFormat; tableFormat.setBorderCollapse(true); tableFormat.setHeaderRowCount(row); cursor.insertTable(row, column); for (int r = 0; r < row; r++) { for (int c = 0; c < column; c++) { auto index = table->model()->index(r, c); cursor.insertText( table->model()->data(index).toString() ); cursor.movePosition(QTextCursor::NextCell); } } doc.print(&printer); }
How to add page header/footer as well as table column header on each page?
@Emon-Haque
You can't. GoogleHeader Footer QTextDocument
. Unless you're keen enough to want to do the low-leveldrawText
/pageRect
stuff to roll your own, e.g. https://forum.qt.io/topic/5152/adding-a-footer-to-a-qtextdocument/2 -
@Emon-Haque
You can't. GoogleHeader Footer QTextDocument
. Unless you're keen enough to want to do the low-leveldrawText
/pageRect
stuff to roll your own, e.g. https://forum.qt.io/topic/5152/adding-a-footer-to-a-qtextdocument/2@JonB, it should have some simpler class to make tabular report. Everyone has those things.
-
Hi,
https://www.kdab.com/development-resources/qt-tools/kd-reports/
https://ncreportsoftware.com/
https://cute-report.com/
http://limereport.sourceforge.net/And there are likely other Qt based tools to build reports.
-
I found this example interesting: https://github.com/jeromecc/qprintereasy
best regards
HoM -
I found this example interesting: https://github.com/jeromecc/qprintereasy
best regards
HoM@HoMa, will look at that soon. Thanks for sharing the link.
-
Hi,
https://www.kdab.com/development-resources/qt-tools/kd-reports/
https://ncreportsoftware.com/
https://cute-report.com/
http://limereport.sourceforge.net/And there are likely other Qt based tools to build reports.
@SGaist, those are heavy library and probably is suitable for business.
What about individuals and others who want to have something like WPF's Fixed/FlowDocuments to create their own lightweight reports?
-
I found this example interesting: https://github.com/jeromecc/qprintereasy
best regards
HoM