[PyQt] Print a QTableView

David Boddie david at boddie.org.uk
Sat Oct 25 02:07:12 BST 2008


On Fri Oct 24 14:35:11 BST 2008, Romain Bignon wrote:
> Romain Bignon wrote:
> > I want to print a QTableView on a QPrinter, but there isn't any way to do
> > that.
>
> I've tried to redirect painter to the printer device, but render is not
> correct.

This probably won't produce high quality output - the best you can expect
is a nice screenshot-style image.

> Firstly, only the region of widget printed on screen is drawn. Then, the
> quality is not good, and some additional widgets in the QTableView (set
> with the setIndexWidget() method) aren't printed.
>
> What other way is there to print the QTableView? It is possible to use
> QPainter to draw myself the table, but it is tedious.
>
> Is there any other solution?

One way is to examine the contents of the table by querying the model and
construct a table in a text document. The style won't match what you
see on screen, but at least you can let the text document figure out how
to print the table.

David


More information about the PyQt mailing list