[SOLVED] Report Engine for Qt?
-
Hi guys,
I have a Qt interface that I would like to be able to print to a report (pdf file)
"Here is the interface":https://www.dropbox.com/s/2hdu00g8rrdtu6k/qwtPlotReport.png?dl=0For now I use QwtPlotRenderer that does a great job as printing the graph to a PDF.
I would also like to incorporate some other data on top of the graph (Name, Description, etc.)
This is a basic report with no request to the database, just some formatting of what I have in the Qt interface and printing it to a PDF.Is there some tools integrated in Qt for that? I have looked at third party option (QtRPT, NcReport) but they don't really fit my needs, I would rather code a routine that print my own PDF.
Thanks!
Current code :
@void WorkoutCreator::exportWorkoutToPdf() {/// TODO: Add Title, remove background image, increase margins ui->widget_plot_report->setTitle(workout.getName().toUpper() + "-" + workout.getPlan()); ui->widget_plot_report->setContentsMargins(20,20,20,20); ui->widget_plot_report->setAxisTitle(2, tr("Time")); QString fileNameToShow = ui->widget_plot_report->getSavePathExport() + QDir::separator() + workout.getName(); QString fileName = QFileDialog::getSaveFileName(this, tr("Export Workout"), fileNameToShow, tr("PDF Documents(*.pdf)")); if (fileName.isEmpty()) return; QwtPlotRenderer renderer; renderer.exportToFile(ui->widget_plot_report, fileName); //Save path for future uses QFileInfo fileInfo(fileName); ui->widget_plot_report->savePathExport(fileInfo.absolutePath()); showStatusBarMessage(tr("Saved to: ") + fileName, 7000);
}@
-
Hi,
Does the "Qt Print Support":http://doc.qt.io/qt-5/qtprintsupport-index.html module fit your needs?
-
You can print to PDF just fine, and that includes printing Qwt plots. However, you should be aware that directly printing widgets doesn't result in pretty reports. The average screen has a dpi resolution that is far lower than a normal DPI for a PDF, let alone for a printer. There can be an order of magnitude difference.
I wrote a report engine for our company in order to work with all that. It is based on Qt's PDF engine and it also prints out Qwt graphs, but it is not trivial to make everything look nice if you start from scratch.
-
Thanks for the response!
Custom report using QPainter looks to be the solution I'll be trying. I won't paint the other widgets directly to the report (except the Qwt plot that already looks fine). I'll format the rest differently using QPainter.
Have a good day,
Max -
Old topic, but for someone who will be looking for a reporting tool like FastReport or Crystal Reports, consider CuteReport.
It has both GPL/LGPL and proprietary Enterprise version and supports graphs with export to PDF:
[URL="https://cute-report.com/"]https://cute-report.com/[/URL]
[URL="https://sourceforge.net/projects/qreport/?"]https://sourceforge.net/projects/qreport/?[/URL]