[Qt-interest] Difference in drawing to a QPixmap VS QPrinter

Christopher Rasch-Olsen Raa christopher at technophile.info
Fri Jul 2 14:01:09 CEST 2010


Hi,

A requirement for an application I'm working on is that it should write a 
certain page of text to a .pdf. For that I'm using QPainter with QPrinter and 
setting the outputformat to Pdf. All is good so far.

However, another requirement is that the application should be able to display 
a "preview" of the document. I though that the quickest way to achieve that 
must be to pass a QPixmap to the QPainter (since QPixmap is a paintdevice) and 
let the same code for painting do it's thing regardless for the 'medium'.

What happens is that I get wildly varying looks on the two documents. The pdf 
looks fine(-ish. lacking some tweaks) but the image (QPixmap) does not. In the 
QPixmap the text is way too large.

I use (pixmap/printer)->width() and ->height() to get the width and height of 
my 'canvas' and position things relative to the edges. When creating the fonts 
I pass the 'device' (a pixmap or printer) to the font's constructor. Is the 
something special I need to do to have the font 'scale' in accordance to the 
size of the available 'canvas'?

Have anyone done this before and have some insight to share?

-- 
Christopher



More information about the Qt-interest-old mailing list