[PyQt] Printing in PyQt

michael h michaelkenth at gmail.com
Sun Feb 22 23:43:00 GMT 2015


>
>
> Hi michael that solved that one now im getting a error saying that
> QPainter::begin: A paint device can only be painted by one painter at a
> time.
>


>From the docs:

QPainter::QPainter(QPaintDevice * device)
Constructs a painter that begins painting the paint device immediately.

>         painter=QtGui.QPainter(printer)

So you're calling begin again here.

>         painter.begin(printer)

So take your own begin() call out.

As a side note, QPainter can actually be used as a context manager so you
could do:

with QPainter(printer) as painter:
     code with painter

and it will handle being()/end() for you as needed

 mh
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20150222/e9314e5d/attachment.html>


More information about the PyQt mailing list