Printing a file

Jeremy Sanders jeremy+complangpython at jeremysanders.net
Tue Feb 28 06:31:40 EST 2006


Fabian Steiner wrote:

> Unfortunately I don't know how to realize this, since also some images
> and different boxes should be printed out. As the whole application is
> based on QT, QPrinter might be used, but I couldn't find any examples
> how to use it.

QPrinter is easy to use. You just draw to the page the same way as you talk
to the screen with a QPainter.

prnt = qt.QPrinter()
# you can also vary options like colour, doc name, dpi here

# display dialog box to user (you can actually leave this out)
if prnt.setup():
     painter = qt.QPainter()
     painter.begin(printer)
     # do stuff to draw to painter
     painter.end(printer)
     # do this between each page
     printer.newPage()

     # ... more pages can be printed to a painter

It's very easy to do. If you want to handle multiple pages and so on,
there's a bit of work to do to interface to the dialog to get the
user-selected page range, etc.

Jeremy

-- 
Jeremy Sanders
http://www.jeremysanders.net/



More information about the Python-list mailing list