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

Christopher Rasch-Olsen Raa christopher at technophile.info
Mon Jul 5 10:18:29 CEST 2010


Mandag 5. juli 2010 09.50.08 skrev Andre Somers :
> On 5-7-2010 9:38, Christopher Rasch-Olsen Raa wrote:
> > Fredag 2. juli 2010 14.14.49 skrev Samuel Gaist :
> >> On 2 juil. 10, at 14:01, Christopher Rasch-Olsen Raa wrote:
> >>> 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?
> >> 
> >> Hi,
> >> 
> >> I can not help you directly for the QPixmap problem but for what you
> >> want to achieve you might be interested by QPrintPreviewWidget or
> >> QPrintPreviewDialog.
> >> 
> >> Hope this helps
> >> Samuel
> > 
> > Thanks for the input, but part of the challenge here is that I need to
> > create tumbnails of several different documents at once and display them
> > to the user side-by-side in the gui, not in different dialoges.
> 
> And the QPrintPreviewWidget is not usable for that? If not, what is it
> that you need that this class does not provide exactly?
> 
> André

There are other requirements like which kind of layout to use in the print 
preview (switching between eg. horiz, vert, grid, etc), supporting reordering 
in the preview and removal of certain pages.

-- 
Christopher




More information about the Qt-interest-old mailing list