[PyKDE] Printing using QPrinter
Fabian Steiner
lists at fabis-site.net
Wed Mar 1 22:49:12 GMT 2006
Hello!
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.
A minimal example would be something like this:
Name: ........... Date: ..............
Role: ............ Departure: ..............
Address: ............
(about 20 other items ...)
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.
Some values should also be shown in tables and lists, so one may speak
of a quite complex layout.
This is what I have so far:
app = QApplication(sys.argv)
printer = QPrinter(QPrinter.PrinterResolution)
if printer.setup():
printer.setPageSize(printer.A4)
painter = QPainter(printer)
metrics = QPaintDeviceMetrics(painter.device())
marginHeight = 6
marginWidth = 8
body = QRect(marginWidth, marginHeight, metrics.width() - 2 * marginWidth, metrics.height() - 2 * marginHeight)
painter.drawRect(body)
painter.end()
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.
Is there any other way to realize my purpose?
Thank you for any input!
Cheers,
Fabian Steiner
More information about the PyQt
mailing list