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 can i print all the content of groupbox in any available printers?
QtWS25 Last Chance

How can i print all the content of groupbox in any available printers?

Scheduled Pinned Locked Moved Unsolved General and Desktop
12 Posts 2 Posters 682 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.
  • I ioanna

    This is an image of the missing part which i wish to include in the printing.

    695bd4d0-453d-42e2-81dd-cbddaf7514f9-image.png

    this is my output which shows it was cut

    this is the the code:

        QPrinter printer;
        QPainter painter;
        Dialog w;
    
    
        QPrintDialog printDialog(&printer);
        if (printDialog.exec() == QDialog::Accepted) {
            painter.begin(&printer);
                        printer.setPaperSize(QPrinter::A4);
                        printer.setPageMargins(2, 2, 2, 10, QPrinter::Millimeter);
                        printer.setFullPage(true);
                        double xscale = printer.pageRect().width() / double(w.width());
                        double yscale = printer.pageRect().height() / double(w.height());
                        double scale = qMin(xscale, yscale);
                        painter.translate(printer.paperRect().center());
                        painter.scale(scale, scale);
                        painter.translate(-w.width()/ 2, -w.height()/ 2);
            ui->groupBox->render(&painter);
          }
    
    jsulmJ Offline
    jsulmJ Offline
    jsulm
    Lifetime Qt Champion
    wrote on last edited by jsulm
    #2

    @ioanna Just use QPrinter returned by https://doc.qt.io/qt-5/qprintdialog.html#printer

    https://forum.qt.io/topic/113070/qt-code-of-conduct

    1 Reply Last reply
    0
    • I Offline
      I Offline
      ioanna
      wrote on last edited by
      #3

      SIr i am a newbie, can you guide me how to use your suggested solution?

      jsulmJ 1 Reply Last reply
      0
      • I ioanna

        SIr i am a newbie, can you guide me how to use your suggested solution?

        jsulmJ Offline
        jsulmJ Offline
        jsulm
        Lifetime Qt Champion
        wrote on last edited by
        #4

        @ioanna There is really nothing special:

        if (printDialog.exec() == QDialog::Accepted) {
            QPrinter *printer = printDialog.printer();
            painter.begin(printer);
        

        https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        0
        • I Offline
          I Offline
          ioanna
          wrote on last edited by
          #5

          It's the same the output is still like this.

          https://drive.google.com/file/d/1WIe7IHVREm-9FTrBl5WAqZ3g-MgjaSj-/view?usp=sharing

          jsulmJ 1 Reply Last reply
          0
          • I ioanna

            It's the same the output is still like this.

            https://drive.google.com/file/d/1WIe7IHVREm-9FTrBl5WAqZ3g-MgjaSj-/view?usp=sharing

            jsulmJ Offline
            jsulmJ Offline
            jsulm
            Lifetime Qt Champion
            wrote on last edited by
            #6

            @ioanna Then I guess your scaling is wrong.

            https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            0
            • I Offline
              I Offline
              ioanna
              wrote on last edited by
              #7

              @jsulm sir i have the same result, i forgot to tell you that during run time the ui was also cut exactly the same with the one being printed. I can't find a way to display what i have designed in my UI form since it is too long with a height of 1.3k.

              jsulmJ 1 Reply Last reply
              0
              • I ioanna

                @jsulm sir i have the same result, i forgot to tell you that during run time the ui was also cut exactly the same with the one being printed. I can't find a way to display what i have designed in my UI form since it is too long with a height of 1.3k.

                jsulmJ Offline
                jsulmJ Offline
                jsulm
                Lifetime Qt Champion
                wrote on last edited by
                #8

                @ioanna It looks like you did not put all your widgets in a layout. Do this first. https://doc.qt.io/qt-5/layout.html

                https://forum.qt.io/topic/113070/qt-code-of-conduct

                1 Reply Last reply
                0
                • I Offline
                  I Offline
                  ioanna
                  wrote on last edited by
                  #9

                  @jsulm is it possible to zoom out to view all my design?

                  jsulmJ 1 Reply Last reply
                  0
                  • I ioanna

                    @jsulm is it possible to zoom out to view all my design?

                    jsulmJ Offline
                    jsulmJ Offline
                    jsulm
                    Lifetime Qt Champion
                    wrote on last edited by
                    #10

                    @ioanna Why don't you put your widgets into a layout instead?
                    You can't "zoom out" if part of your UI is not fitting into the window.

                    https://forum.qt.io/topic/113070/qt-code-of-conduct

                    1 Reply Last reply
                    0
                    • I Offline
                      I Offline
                      ioanna
                      wrote on last edited by ioanna
                      #11

                      @jsulm sir thanks. But i have a last question, can i stretch widgets to fit in A4 size?

                      jsulmJ 1 Reply Last reply
                      0
                      • I ioanna

                        @jsulm sir thanks. But i have a last question, can i stretch widgets to fit in A4 size?

                        jsulmJ Offline
                        jsulmJ Offline
                        jsulm
                        Lifetime Qt Champion
                        wrote on last edited by
                        #12

                        @ioanna If your UI is showing correctly (using layouts) then you will need to scale it when printing, so it fits A4.

                        https://forum.qt.io/topic/113070/qt-code-of-conduct

                        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