[Interest] QPdfWriter rendering images with a Proxy PaintDevice is literally off

Jason H jhihn at gmx.com
Sat Dec 20 17:31:48 CET 2014


Ok, so I got the bright idea to make a printing system based on QLayouts. This saves me from ding a lot of calculations and is dearly perfect. But there are a few rough corners and one that I cannot figure out. 

First the approach:
I use ui files to create multiple UI Widgets which are then directed at a painter, via QWidget::render();
This largely works, but I have to 
1. Size the Widget tree to the print device width - varies on your DPI (300, 600, 1200 dpi)
2. Scale fonts in relation to the screen DPI (300 dpi / 72 DPI = 4) so for all the text, set the font to 4x
3. Use a proxy painter to prevent the render() from calling painter end() which tells PdfWriter to close the file. My proxy painter does not implement end() in a meaningful way, I have a realEnd() that does it.
4. Looping through the widgets, move the vertical offset down the page by the last widget's height(), when a widget won't fit on a page, call newPage() and reset the vertical offset to 0
-- the above works, below is the problem --
5. When using drawPixmap(), the coordinates seem to be translated relative to a container. That is, if I place a QFrame where the image should be, the frame is drawn in the right place. The image is drawn at some offset to that, usually only partially in the box, lower and further right. If I modify the proxy painter to reset the top left of the dest rest to 0,0, then the image is drawn in the box.  

If anything was the case, I wound expect it to work, not to have some wacky offset, since children are painted relative to their parent. I'm thinking I need some QPainter save() restore() functionality, but I'm not sure how that is supposed to work. If it worked as I expected, the image would be at 0,0 of the document. 

How can I get this working?



More information about the Interest mailing list