Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Unsolved Resize A Picture When Print it

    General and Desktop
    resize picture screen capture print
    3
    8
    5895
    Loading More Posts
    • 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.
    • M4RZB4Ni
      M4RZB4Ni last edited by

      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 Reply Quote 0
      • E
        euchkatzl last edited by

        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 Reply Quote 2
        • M4RZB4Ni
          M4RZB4Ni last edited by

          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 Reply Quote 0
          • mrjj
            mrjj Lifetime Qt Champion last edited by

            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.

            M4RZB4Ni 1 Reply Last reply Reply Quote 1
            • M4RZB4Ni
              M4RZB4Ni @mrjj last edited by

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

              Thanks
              M4RZB4Ni

              1 Reply Last reply Reply Quote 0
              • mrjj
                mrjj Lifetime Qt Champion last edited by

                Hi
                He dont use print dialog.

                M4RZB4Ni 1 Reply Last reply Reply Quote 0
                • M4RZB4Ni
                  M4RZB4Ni @mrjj last edited by

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

                  Thanks
                  M4RZB4Ni

                  mrjj 1 Reply Last reply Reply Quote 0
                  • mrjj
                    mrjj Lifetime Qt Champion @M4RZB4Ni last edited by mrjj

                    @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 Reply Quote 1
                    • First post
                      Last post