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. Preview & Scaling in Printer Dialog
Forum Updated to NodeBB v4.3 + New Features

Preview & Scaling in Printer Dialog

Scheduled Pinned Locked Moved Unsolved General and Desktop
12 Posts 3 Posters 1.3k Views 2 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.
  • ademmlerA Offline
    ademmlerA Offline
    ademmler
    wrote on last edited by ademmler
    #1

    Hi to all,

    can somebody pls tell me if such a Printer Dialog with "Preview" and "Scaling Option" is available by default from QPrintDialog?

    print.png

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

      Hi,

      AFAIR, on macOS, it's the system dialog that is shown so you should have your OS standard feature in there.

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

      ademmlerA 1 Reply Last reply
      1
      • SGaistS SGaist

        Hi,

        AFAIR, on macOS, it's the system dialog that is shown so you should have your OS standard feature in there.

        ademmlerA Offline
        ademmlerA Offline
        ademmler
        wrote on last edited by
        #3

        @SGaist That is what I thought also, but it does not appear.
        I get hat you can see below. It is missing the Preview, Auto-Rotate and "Fit to Size" Options.

        Bildschirmfoto 2024-02-08 um 10.36.03.png

        SGaistS 1 Reply Last reply
        0
        • ademmlerA ademmler

          @SGaist That is what I thought also, but it does not appear.
          I get hat you can see below. It is missing the Preview, Auto-Rotate and "Fit to Size" Options.

          Bildschirmfoto 2024-02-08 um 10.36.03.png

          SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @ademmler what about QPrintPreviewDialog ?

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

          ademmlerA 1 Reply Last reply
          1
          • SGaistS SGaist

            @ademmler what about QPrintPreviewDialog ?

            ademmlerA Offline
            ademmlerA Offline
            ademmler
            wrote on last edited by
            #5

            @SGaist hi, it does not look like Mac Native Dialog.

            Bildschirmfoto 2024-02-13 um 09.37.04.png

            Ronel_qtmasterR 1 Reply Last reply
            0
            • ademmlerA ademmler

              @SGaist hi, it does not look like Mac Native Dialog.

              Bildschirmfoto 2024-02-13 um 09.37.04.png

              Ronel_qtmasterR Offline
              Ronel_qtmasterR Offline
              Ronel_qtmaster
              wrote on last edited by
              #6

              @ademmler it seems that you will have to implement you own

              ademmlerA 1 Reply Last reply
              0
              • Ronel_qtmasterR Ronel_qtmaster

                @ademmler it seems that you will have to implement you own

                ademmlerA Offline
                ademmlerA Offline
                ademmler
                wrote on last edited by
                #7

                @Ronel_qtmaster Yes maybe - but still laundering, because the first image I have send is MacNative Dialog.
                I check further into this.

                SGaistS 1 Reply Last reply
                0
                • ademmlerA ademmler

                  @Ronel_qtmaster Yes maybe - but still laundering, because the first image I have send is MacNative Dialog.
                  I check further into this.

                  SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  @ademmler Can you provide a minimal compilable example so that we can check things on the same level ?

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

                  ademmlerA 1 Reply Last reply
                  0
                  • SGaistS SGaist

                    @ademmler Can you provide a minimal compilable example so that we can check things on the same level ?

                    ademmlerA Offline
                    ademmlerA Offline
                    ademmler
                    wrote on last edited by
                    #9

                    @SGaist Sure - I have put both Dialogs into one example - you can choose which one to use at the top of main.cpp.

                    #include <QApplication>
                    #include <QPrinter>
                    #include <QPrintDialog>
                    #include <QPrintPreviewDialog>
                    #include <QPainter>
                    
                    #define usePreview 0
                    
                    class MyPrintPreviewDialog : public QPrintPreviewDialog
                    {
                    public:
                        MyPrintPreviewDialog(QPrinter *printer, QWidget *parent = nullptr)
                            : QPrintPreviewDialog(printer, parent)
                        {
                            // Connect the signal for generating the preview
                            connect(this, &QPrintPreviewDialog::paintRequested, this, &MyPrintPreviewDialog::printPreview);
                        }
                    
                    private:
                        void printPreview(QPrinter *printer)
                        {
                            // Create a QPainter to draw on the printer
                            QPainter painter(printer);
                            
                            // Draw some text on the printer
                            painter.drawText(QRect(20, 20, 200, 200), "Hello, World!");
                        }
                    };
                    
                    
                    int main(int argc, char *argv[])
                    {
                        QApplication app(argc, argv);
                    
                    #if usePreview
                        // Create a printer object
                        QPrinter printer;
                    
                        // Create a print preview dialog
                        MyPrintPreviewDialog dialog(&printer);
                        // Show the print preview dialog
                        dialog.exec();
                    #else
                        // Create a printer object
                        QPrinter printer;
                    
                        printer.setPageSize(QPrinter::A4);
                        printer.setOrientation(QPrinter::Portrait);
                        printer.setResolution(300);
                    
                        // Create a print dialog and get print settings from the user
                        QPrintDialog printDialog(&printer);
                        if (printDialog.exec() != QDialog::Accepted) {
                            return 0; // User canceled the print dialog
                        }
                    
                        // Create a QPainter object and set it to draw on the printer
                        QPainter painter(&printer);
                    
                        // Use the QPainter to draw on the printer
                        painter.drawText(QRect(100, 100, 200, 200), "Hello, World!");
                        painter.drawLine(QPointF(0, 0), QPointF(100, 100));
                        // ...
                    
                        // End the painting and release the printer
                        painter.end();
                    #endif
                    
                        return app.exec();
                    }
                    

                    QtCreator project file:

                    ######################################################################
                    # Automatically generated by qmake (3.1) Tue Feb 13 09:33:07 2024
                    ######################################################################
                    
                    QT       += core gui network printsupport
                    
                    TEMPLATE = app
                    TARGET = trial
                    INCLUDEPATH += .
                    
                    # Input
                    SOURCES += main.cpp
                    
                    SGaistS 1 Reply Last reply
                    1
                    • ademmlerA ademmler

                      @SGaist Sure - I have put both Dialogs into one example - you can choose which one to use at the top of main.cpp.

                      #include <QApplication>
                      #include <QPrinter>
                      #include <QPrintDialog>
                      #include <QPrintPreviewDialog>
                      #include <QPainter>
                      
                      #define usePreview 0
                      
                      class MyPrintPreviewDialog : public QPrintPreviewDialog
                      {
                      public:
                          MyPrintPreviewDialog(QPrinter *printer, QWidget *parent = nullptr)
                              : QPrintPreviewDialog(printer, parent)
                          {
                              // Connect the signal for generating the preview
                              connect(this, &QPrintPreviewDialog::paintRequested, this, &MyPrintPreviewDialog::printPreview);
                          }
                      
                      private:
                          void printPreview(QPrinter *printer)
                          {
                              // Create a QPainter to draw on the printer
                              QPainter painter(printer);
                              
                              // Draw some text on the printer
                              painter.drawText(QRect(20, 20, 200, 200), "Hello, World!");
                          }
                      };
                      
                      
                      int main(int argc, char *argv[])
                      {
                          QApplication app(argc, argv);
                      
                      #if usePreview
                          // Create a printer object
                          QPrinter printer;
                      
                          // Create a print preview dialog
                          MyPrintPreviewDialog dialog(&printer);
                          // Show the print preview dialog
                          dialog.exec();
                      #else
                          // Create a printer object
                          QPrinter printer;
                      
                          printer.setPageSize(QPrinter::A4);
                          printer.setOrientation(QPrinter::Portrait);
                          printer.setResolution(300);
                      
                          // Create a print dialog and get print settings from the user
                          QPrintDialog printDialog(&printer);
                          if (printDialog.exec() != QDialog::Accepted) {
                              return 0; // User canceled the print dialog
                          }
                      
                          // Create a QPainter object and set it to draw on the printer
                          QPainter painter(&printer);
                      
                          // Use the QPainter to draw on the printer
                          painter.drawText(QRect(100, 100, 200, 200), "Hello, World!");
                          painter.drawLine(QPointF(0, 0), QPointF(100, 100));
                          // ...
                      
                          // End the painting and release the printer
                          painter.end();
                      #endif
                      
                          return app.exec();
                      }
                      

                      QtCreator project file:

                      ######################################################################
                      # Automatically generated by qmake (3.1) Tue Feb 13 09:33:07 2024
                      ######################################################################
                      
                      QT       += core gui network printsupport
                      
                      TEMPLATE = app
                      TARGET = trial
                      INCLUDEPATH += .
                      
                      # Input
                      SOURCES += main.cpp
                      
                      SGaistS Offline
                      SGaistS Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on last edited by
                      #10

                      The preview dialog is indeed non-native but the setup part is.

                      As for having the preview in the print dialog, you would have to modify the backend part to set it up.

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

                      ademmlerA 1 Reply Last reply
                      0
                      • SGaistS SGaist

                        The preview dialog is indeed non-native but the setup part is.

                        As for having the preview in the print dialog, you would have to modify the backend part to set it up.

                        ademmlerA Offline
                        ademmlerA Offline
                        ademmler
                        wrote on last edited by
                        #11

                        @SGaist Thx for checking this out. Do I understand you right - did you ment to take the default QPrinter class and add more "setup functionality" aka native code to get the OS related preview activated?

                        SGaistS 1 Reply Last reply
                        0
                        • ademmlerA ademmler

                          @SGaist Thx for checking this out. Do I understand you right - did you ment to take the default QPrinter class and add more "setup functionality" aka native code to get the OS related preview activated?

                          SGaistS Offline
                          SGaistS Offline
                          SGaist
                          Lifetime Qt Champion
                          wrote on last edited by
                          #12

                          @ademmler no, lower level, down to the platform plugin.

                          Interested in AI ? www.idiap.ch
                          Please read the Qt Code of Conduct - 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