Printing a file
Fabian Steiner
lists at fabis-site.net
Wed Mar 1 10:38:23 EST 2006
Hi!
Thank you so far, but now I got stuck again :-/
Jeremy Sanders wrote:
> 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()
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.widthMM() - 2 *
marginWidth, metrics.heightMM() - 2 * marginHeight)
painter.drawRect(body)
painter.end()
Doing so I hoped to get a rectangle which is as big as an A4 paper (with
a small border), but unfortunately it is much smaller. Moreover, I ask
myself whether it is necessary that in order to write text on the paper,
I always have to pass the proper x, y values to QPainter.drawText().
Isn't there any other possibility? How do I get these values?
Thanks in advance,
Fabian Steiner
More information about the Python-list
mailing list