[PyKDE] Printing using QPrinter

David Boddie david at boddie.org.uk
Sat Mar 4 01:26:54 GMT 2006


On Wed, 01 Mar 2006 23:49:12, Fabian Steiner wrote:

> I am currently working on an application where the user is able to
> create new worksheets and to delete existing ones. All of these
> worksheets have the same structure, only some values should be changed.

[...]

> The values are stored in a SQLite database. Now I would like to offer
> the possibility to print out a single record on a DinA4 paper. In order
> to do this, the dots (...) above of course have to be replaced by the
> current record's values and the different parts have to fit on one page.

OK. We'll assume that it's always possible to fit everything on one page.

> Some values should also be shown in tables and lists, so one may speak
> of a quite complex layout.

We're going to use a subset of HTML, so all of this should be possible.

> This is what I have so far:

[Code snipped]

> body is the border of the whole page, the other objects should be placed
> in it, but I don't know how to position the other elements. Of course, I
> can pass the appropriate x, y values to QPainter.drawText(), but it
> means a lot of work to get them for about 25 elements.

This is where you should probably use the text layout facilities provided
by Qt. In Qt 3, it looks like the best way to do this is with QTextEdit or
QTextBrowser to display the text, and by using QSimpleRichText with
QPrinter to print it.

I thought it might be a worthwhile learning experience to prototype
something that does a little of what you want, and put it up on the
PyQt Wiki:

http://www.diotavelli.net/PyQtWiki/Printing_a_Worksheet

Feel free to update it so that others can benefit from your experience.

Have fun,

David




More information about the PyQt mailing list