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 two separate pages
Qt 6.11 is out! See what's new in the release blog

Print two separate pages

Scheduled Pinned Locked Moved Solved General and Desktop
7 Posts 3 Posters 1.0k Views 1 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.
  • I Offline
    I Offline
    isan
    wrote on last edited by isan
    #1

    I have two pages that I want to print
    Now I can print them separately by calling the printer and the painter twice,
    But I want to call the printer once, and print them
    How can I do it?

    QPixmap pix =ui->stackedWidget->widget(0)->grab();
    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); 
          painter.drawPixmap(0, 0, pix);
          painter.end();
    
    QPrinter printer;
    
           QPrintDialog dlg(&printer, 0);
           if (dlg.exec() == QDialog::Accepted) {
    
               // Output chart as QImage
               /// do some thing
    
               // Print the image
               QPainter painter(&printer);
               painter.drawImage(QPoint(80,0),image);
               painter.end();
           }
    
    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Is QPrinter::newPage what you are looking for ?

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

      I 2 Replies Last reply
      3
      • SGaistS SGaist

        Hi,

        Is QPrinter::newPage what you are looking for ?

        I Offline
        I Offline
        isan
        wrote on last edited by isan
        #3

        @sgaist It's work tnx

                     painter.drawPixmap(0, 0, pix);
                     printer.newPage();
                     painter.drawImage(QPoint(80,0),image);
                
                }
        
        
        1 Reply Last reply
        0
        • SGaistS SGaist

          Hi,

          Is QPrinter::newPage what you are looking for ?

          I Offline
          I Offline
          isan
          wrote on last edited by
          #4

          @sgaist I have another problem
          the page has scrollBar
          When I grab It

          QPixmap pix = ui-> stackedWidget-> widget (0) -> grab ();
          

          , Prints half of the page
          How do I print the entire page??

          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #5

            What kind of widget is that ?

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

            zhmhZ I 2 Replies Last reply
            0
            • SGaistS SGaist

              What kind of widget is that ?

              zhmhZ Offline
              zhmhZ Offline
              zhmh
              wrote on last edited by zhmh
              #6

              a page? do you mean a widget?

              1 Reply Last reply
              0
              • SGaistS SGaist

                What kind of widget is that ?

                I Offline
                I Offline
                isan
                wrote on last edited by isan
                #7

                @sgaist
                I want to print a page of the stack widget that has the scroll bar
                This page contains line Edit, Push Button
                It's solve with :

                QPixmap pix = ui->scrollAreaWidgetContents->grab();
                
                1 Reply Last reply
                0

                • Login

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