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. Resize A Picture When Print it
QtWS25 Last Chance

Resize A Picture When Print it

Scheduled Pinned Locked Moved Unsolved General and Desktop
resizepicturescreen captureprint
8 Posts 3 Posters 6.9k Views
  • 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.
  • M Offline
    M Offline
    M4RZB4Ni
    wrote on 29 Aug 2016, 20:37 last edited by
    #1

    Hello
    i have a app that take a screenshot of window and i want to Print that Image
    but i want to when i want to print program fit the image with paper size like A4 Size
    how i can resize the image when Printing?
    and i have second Question
    What is The Base Of sizes in Qt?
    Inch?Pixel?Centimeter?
    Thanks a lot

    Thanks
    M4RZB4Ni

    1 Reply Last reply
    0
    • E Offline
      E Offline
      euchkatzl
      wrote on 30 Aug 2016, 05:11 last edited by
      #2

      I think the best opportunity would be to generate a pdf and then print that.

      QPrinter printer(QPrinter::HighResolution);
      printer.setOutputFormat(QPrinter::PdfFormat);
      printer.setResolution(300);
      printer.setOutputFileName("patth/to/your/pdffile.pdf");
      printer.setPageMargins(0,0,0,0, QPrinter::Millimeter);
      
      printer.setPaperSize(QPrinter::A4);
      
      QPainter painter(&printer);
      painter.drawImage(0,0,QImage());
      painter.end();
      

      For the base of size take a look at http://doc.qt.io/qt-5/qprinter.html#Unit-enum.

      1 Reply Last reply
      2
      • M Offline
        M Offline
        M4RZB4Ni
        wrote on 31 Aug 2016, 11:28 last edited by
        #3

        thanks so much
        but i want only print a .png file in a directory not a pdf!
        can you Guidance ?

        Thanks
        M4RZB4Ni

        1 Reply Last reply
        0
        • M Offline
          M Offline
          mrjj
          Lifetime Qt Champion
          wrote on 31 Aug 2016, 11:39 last edited by
          #4

          Hi
          He do not print a PDF in that code.
          He print Image to a pdf file.
          You should read the docs.
          Many good examples.

          M 1 Reply Last reply 31 Aug 2016, 11:44
          1
          • M mrjj
            31 Aug 2016, 11:39

            Hi
            He do not print a PDF in that code.
            He print Image to a pdf file.
            You should read the docs.
            Many good examples.

            M Offline
            M Offline
            M4RZB4Ni
            wrote on 31 Aug 2016, 11:44 last edited by
            #5

            @mrjj
            yes you say right :)
            Thanks
            and if i want print without print Dialog how should do that?

            Thanks
            M4RZB4Ni

            1 Reply Last reply
            0
            • M Offline
              M Offline
              mrjj
              Lifetime Qt Champion
              wrote on 31 Aug 2016, 11:45 last edited by
              #6

              Hi
              He dont use print dialog.

              M 1 Reply Last reply 31 Aug 2016, 11:46
              0
              • M mrjj
                31 Aug 2016, 11:45

                Hi
                He dont use print dialog.

                M Offline
                M Offline
                M4RZB4Ni
                wrote on 31 Aug 2016, 11:46 last edited by
                #7

                @mrjj
                i do this but my image in PDF file is not full screen!
                its very small in PDF File!

                Thanks
                M4RZB4Ni

                M 1 Reply Last reply 31 Aug 2016, 11:48
                0
                • M M4RZB4Ni
                  31 Aug 2016, 11:46

                  @mrjj
                  i do this but my image in PDF file is not full screen!
                  its very small in PDF File!

                  M Offline
                  M Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on 31 Aug 2016, 11:48 last edited by mrjj
                  #8

                  @M4RZB4Ni
                  yes, that is normal.
                  Printer have many more pixels. so image seem smaller.
                  Read docs.
                  they have example of scaling stuff.
                  This sample takes snapshot and scales it.

                  void MainWindow::printshot() {
                    QPixmap pix = QPixmap::grabWindow(QApplication::desktop()->winId());
                    QPrinter printer(QPrinter::HighResolution);
                    printer.setOrientation(QPrinter::Landscape);
                  
                    QPainter painter;
                    painter.begin(&printer);
                    double xscale = printer.pageRect().width() / double(pix.width());
                    double yscale = printer.pageRect().height() / double(pix.height());
                    double scale = qMin(xscale, yscale);
                    painter.translate(printer.paperRect().x() + printer.pageRect().width() / 2,
                                      printer.paperRect().y() + printer.pageRect().height() / 2);
                    painter.scale(scale, scale);
                    painter.translate(-width() / 2, -height() / 2); // note uses the form width/height! use pix.h/w if random image
                    painter.drawPixmap(0, 0, pix);
                    painter.end();
                  }
                  
                  1 Reply Last reply
                  1

                  1/8

                  29 Aug 2016, 20:37

                  • Login

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