When requesting to the Database I use QSqlQueryModel, I add this model to QTableView, everything is fine, it is displayed. I need to convert this sign to PDF. I know how to make QWebView to PDF with QPrinter and QWebView :: print (). But there was a difficulty when converting from QTableView to QWebView. Of course, you can take individual elements of cells and fill in with html tags, but is there a more elegant way to do this conversion?
1 answer
Any QWidget, including QTableView, can be printed as pdf.
void printToPDF( QWidget* w ) { QPrinter printer(QPrinter::HighResolution); printer.setOutputFormat(QPrinter::PdfFormat); printer.setOutputFileName("output.pdf"); // printer.setPageMargins(12, 16, 12, 20, QPrinter::Millimeter); // printer.setFullPage(false); // ... QPainter painter(&printer); // painter.translate( ..., ... ); // painter.scale( ..., ... ); w -> render(&painter); } But, with a high probability, the client is not satisfied, because he needs not what he sees on the screen, but something else ... It’s easier to go around all the lines / cells in a loop and create an HTML document manually, with styles, footers, and t .d., and then print it in PDF.
|