3

Qt has built-in PDF export support (QPrinter::PdfFormat).

What's the best way to print an SQL table to a PDF file? (a table from a database loaded with QSqlDatabase and linked to a QTableView)...

yolo
  • 2,757
  • 6
  • 36
  • 65

1 Answers1

0

You use QWidget::render. See the documentation about Printing Widgets.

hmuelner
  • 8,093
  • 1
  • 28
  • 39
  • tried it - gives bitmapped results (only an image of the widget) - text would be better – yolo May 14 '11 at 11:41
  • 1
    That's surprising. But if you think about it and read the documentation carefully, you can expect it. I tried printing to pdf with the richtext/orderform example, and the printing of a QTextEdit produces a pdf file with text. My conclusion: Write your table to a QTextDocument and call its print method. – hmuelner May 14 '11 at 12:22
  • 1
    Re writing to QTextDocument: You have to generate HTML with a table and use QTextDocument::setHtml. – hmuelner May 15 '11 at 13:06
  • If you want your pdf to containt text, you can try this one https://github.com/T0ny0/Qt-Table-Printer – Tony O Apr 05 '16 at 10:52