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. Print QPixmap
Qt 6.11 is out! See what's new in the release blog

Print QPixmap

Scheduled Pinned Locked Moved Solved General and Desktop
8 Posts 3 Posters 1.8k 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.
  • P Offline
    P Offline
    Piotrek102
    wrote on last edited by
    #1

    Hello,
    I would like to print a pixmap to a pdf file and via QPrintDialog also on paper. However, I have a problem, every time the pixmap prints as a very small image. How can I enlarge it to a full page up to A4?

    QPixmap pixmap = this->grab();
    QPrinter printer(QPrinter::HighResolution);
    printer.setPageMargins(QMarginsF(0,0,0,0));
    QPainter painter;
    painter.begin(&printer);
    painter.drawPixmap (0, 0, pixmap.scaled(600, 800));
    painter.end();
    QPrintDialog dialog(&printer);
    dialog.exec();
    

    Zrzut ekranu 2022-07-11 190601.png

    1 Reply Last reply
    0
    • Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Please take a look into the documentation on how to scale a pixmap so it fits to your page.

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      1 Reply Last reply
      1
      • JoeCFDJ Offline
        JoeCFDJ Offline
        JoeCFD
        wrote on last edited by JoeCFD
        #3

        https://doc.qt.io/qt-5/qprinter.html#setPageSize
        try to create a svg file for scaling. You can easily lose resolution with image for scaling.

        1 Reply Last reply
        0
        • P Offline
          P Offline
          Piotrek102
          wrote on last edited by
          #4

          Ok, but I have the following errors now
          Zrzut ekranu 2022-07-11 193814.png

          1 Reply Last reply
          0
          • JoeCFDJ Offline
            JoeCFDJ Offline
            JoeCFD
            wrote on last edited by
            #5

            https://doc.qt.io/qt-5/qprinter.html#paperRect-1 you need unit

            Christian EhrlicherC 1 Reply Last reply
            0
            • JoeCFDJ JoeCFD

              https://doc.qt.io/qt-5/qprinter.html#paperRect-1 you need unit

              Christian EhrlicherC Offline
              Christian EhrlicherC Offline
              Christian Ehrlicher
              Lifetime Qt Champion
              wrote on last edited by Christian Ehrlicher
              #6

              @JoeCFD said in Print QPixmap:

              https://doc.qt.io/qt-5/qprinter.html#paperRect-1 you need unit

              No, pageRect() without a unit was deprecated in Qt5 and removed in Qt6 but the documentation here was not adjusted (will do asap). The deprecation documentation tells how to replace it:

              "Use pageLayout().fullRectPixels(resolution()) instead."

              Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
              Visit the Qt Academy at https://academy.qt.io/catalog

              1 Reply Last reply
              2
              • P Offline
                P Offline
                Piotrek102
                wrote on last edited by
                #7

                Ok, I made it with this code

                working.png

                I got the pdf scaled to the page as I wanted, thank you for your help!

                Christian EhrlicherC 1 Reply Last reply
                1
                • P Piotrek102

                  Ok, I made it with this code

                  working.png

                  I got the pdf scaled to the page as I wanted, thank you for your help!

                  Christian EhrlicherC Offline
                  Christian EhrlicherC Offline
                  Christian Ehrlicher
                  Lifetime Qt Champion
                  wrote on last edited by Christian Ehrlicher
                  #8

                  @Piotrek102 Thx for the information, the Qt6 documentation will be updated shortly. Please mark the topic as solved then.

                  /gerrit commit for reference: https://codereview.qt-project.org/c/qt/qtbase/+/421268

                  Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                  Visit the Qt Academy at https://academy.qt.io/catalog

                  1 Reply Last reply
                  1

                  • Login

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