RichText printing with HighResolution printer
Hi there,
I have trouble printing a rich text document to a printer with HighResolution settings.
So far I use something in the lines of:
Code:
context.
palette.
setColor(QPalette::Text, painter
->pen
().
color());
layout->draw(painter, context);
whereas text is a QTextDocument, and painter is a QPainter created for a printer object. The printer was initialized with QPrinter::HighResolution.
It seems that printing with high-resolution is somewhat tricky. For example, the font metrics returned have to be scaled manually to obtain a correct line spacing. And maybe that's also the reason why the draw() function of QAbstractTextDocumentLayout doesn't work as expected?
Any suggestions are welcome!
Andreas
Re: RichText printing with HighResolution printer
Heureka!
The Qt-Documentation is somewhat sparse at this point. In any case when printing with HighResolution you always have to specify the QPaintDevice before drawing. This applies to QFontMetrics where you need to instantiate the instance with
Also, for the rich-text printing, you need to set the QPaintDevice before drawing. The code snipped below shows how it works:
Code:
layout->setPaintDevice(painter->device()); // this is needed for HighRes printing
context.
palette.
setColor(QPalette::Text, painter
->pen
().
color());
layout->draw(painter, context);