Results 1 to 5 of 5

Thread: [SOLVED] Using QPainter to Import JPG for PDF Report

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Feb 2006
    Location
    Jarrell, Texas, USA
    Posts
    70
    Thanks
    7
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: [SOLVED] Using QPainter to Import JPG for PDF Report

    PDFWriter.width() = 9583
    PDFWriter.height() = 13699

    Karl


    Added after 18 minutes:


    The scaling concept helped.
    Here's how I got a logo that looks appealing.
    I do not want the logo to consume more than a third of the width of the page nor a fifth of height.
    So I scaled using these values:

    Qt Code:
    1. // Scaled images
    2. quint32 iWidth = pdfWriter.width();
    3. quint32 iHeight = pdfWriter.height();
    4. QSize s(iWidth/3, iHeight/5);
    5. QPixmap pxScaledPic = pxPic.scaled(s, Qt::KeepAspectRatio, Qt::FastTransformation);
    6. painter.drawPixmap(0, iYPos, pxScaledPic.width(), pxScaledPic.height(), pxScaledPic);
    7. iYPos += pxScaledPic.height() + 250;
    To copy to clipboard, switch view to plain text mode 

    Thanks for the help.

    Karl
    Last edited by KaptainKarl; 20th October 2014 at 20:59.

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: [SOLVED] Using QPainter to Import JPG for PDF Report

    In general, for good quality print output you need much larger images that render at the right physical size at the print resolution (or that you scale down). So, for example, at 300DPI you need a 600x300 pixel image to get a 2x1 inch image on paper.

    What is the output like if you use the original pixmap and specify the drawPixmap() width and height in painter cordinates? These look like they might be 300 DPI or thereabouts.

    Do you get the QImage result if you call QPainetr::end() before you exit the program?

  3. #3
    Join Date
    Feb 2006
    Location
    Jarrell, Texas, USA
    Posts
    70
    Thanks
    7
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: [SOLVED] Using QPainter to Import JPG for PDF Report

    Unfortunately I will not have control over the size of the image.
    I can only make suggestions to the customer as to what will look best.
    I will include comments similar to yours in the documentation.

    The output of drawPixMap with adjusted width and height arguments does not look as good as the scaled QPixmap.

    Putting painter.end() at the bottom of the program eliminated all the images; QPixmap and QImage.

    Karl

Similar Threads

  1. Report library for QT
    By blackliteon in forum Qt Programming
    Replies: 5
    Last Post: 20th October 2014, 08:23
  2. Replies: 0
    Last Post: 17th November 2009, 20:59
  3. QT report
    By triperzz in forum Qt Programming
    Replies: 3
    Last Post: 25th February 2008, 17:58
  4. Crash report
    By Lele in forum Qt Programming
    Replies: 6
    Last Post: 10th October 2007, 09:50
  5. error report
    By Rekha in forum Newbie
    Replies: 1
    Last Post: 14th August 2006, 12:11

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.