[Interest] How to prevent painter from ending() on render()

Jason H jhihn at gmx.com
Wed Jan 28 21:10:45 CET 2015


> Sent: Wednesday, January 28, 2015 at 1:23 PM
> From: "Giuseppe D'Angelo" <giuseppe.dangelo at kdab.com>
> To: interest at qt-project.org
> Subject: Re: [Interest] How to prevent painter from ending() on render()
>
> Il 28/01/2015 18:50, Jason H ha scritto:
> > So how can someone render multiple widgets on multiple pages? It seems the only option is manual draw***() commands on the painter, but that is tedious, and Qt has a nice Layout manager system...
> 
> 1) Have you tried first opening a QFile, then using QPDFWriter's ctor 
> that takes a QIODevice? I would be really annoyed if closing the painter 
> would close the device on my back. Annoyed to the point to call it a Qt bug.
> 
> 2) Have you tried painting the widget on a QPicture, then replaying the 
> QPicture on the PDF?

I got on IRC, and got a suggestion to have it work by wrapping the render call in an QPainter wrapping the QPdfWriter.

_printer = new QPdfWriter (filename);
_printer->setResolution(150);
QPainter widgetRenderer(_printer);
section->render(&widgetRenderer, QPoint(0, verticalOffset), QRegion(),QWidget::DrawChildren);

The intermediary widgetRenderer doesn't end the painting on the PDF. :-)



More information about the Interest mailing list