Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to print an image and scale it to fit page?
Forum Updated to NodeBB v4.3 + New Features

How to print an image and scale it to fit page?

Scheduled Pinned Locked Moved General and Desktop
printimagescale to fit
5 Posts 3 Posters 5.0k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    pmh4514
    wrote on 9 Mar 2015, 13:57 last edited by
    #1

    Hello,
    I use the following code to successfully print an image, but it fills the entire 8.5x11 piece of paper and is chopped off on the sides. What must I add so that it scales to fit the page?
    Thanks!

    QImage img = myPixmap.toImage(); // myPixmap previously exists
    QPrinter printer;
    QPrintDialog *dlg = new QPrintDialog(&printer,0);
    if(dlg->exec() == QDialog::Accepted) {
        QPainter painter(&printer);
        painter.drawImage(QPoint(0,0),img);
        painter.end();
    }
    
    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 9 Mar 2015, 21:40 last edited by
      #2

      Hi,

      It's been some time but isn't it something you set in the QPrintDialog ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • P Offline
        P Offline
        pmh4514
        wrote on 10 Mar 2015, 12:58 last edited by
        #3

        That was my first thought too, but apparently not. (unless that's due to my own printer..)

        1 Reply Last reply
        0
        • J Offline
          J Offline
          jalomic
          wrote on 10 Mar 2015, 13:13 last edited by
          #4

          @pmh4514 said:

          QPainter

          You can get paper size from printer and draw image by this function
          void QPainter::drawImage ( const QRectF & target, const QImage & image, const QRectF & source, Qt::ImageConversionFlags flags = Qt::AutoColor )

          1 Reply Last reply
          0
          • P Offline
            P Offline
            pmh4514
            wrote on 10 Mar 2015, 15:22 last edited by
            #5

            it doesn't seem to matter what rectangle values I pass to drawImage, or if it's based on the paper size or even if I try a dummy rect that is like (0,0,50,50) - the resulting print still occupies the entire 8.5x11 sheet of paper and is cutoff on the right..

            1 Reply Last reply
            0

            2/5

            9 Mar 2015, 21:40

            • Login

            • Login or register to search.
            2 out of 5
            • First post
              2/5
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved