Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-126522

The QPrintDialog launched from QPrintPreviewDialog updates the current printer when cancelled

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P2: Important
    • None
    • 5.15, 6.2, 6.5, 6.6, 6.7, 6.8
    • GUI: Printing
    • None
    • All

    Description

      QPrintPreviewDialog uses the given (if any) QPrinter to create previews and calls the slot connected to paintRequested with that printer or the one selected in the QPrintDialog if the user wants to finalize printing by clicking the "Print" button in the tool bar.

      If the user changes printer in new the QPrintDialog and accepts it, the connected slot will return a possibly "new" printer, which may not be intuitive (since it may not be completely consistent with the preview) but acceptable.

      The problem comes when the user rejects the QPrintDialog and the selected printer was not the one previously chosen during initialization of QPrintPreviewDialog: the connected slot always uses the one selected in the print dialog even when cancelled.

      A cancelled dialog should have no effect on what originated it, so it should not affect the slot connected to paintRequested at that point.

      While this may seem trivial, it is still inconsistent (other than undocumented) and may create various levels of issues for anything that could be implemented in the connected slot; for instance, if the function has to consider important aspects to create appropriate preview/printed pages while considering actual page size capabilities, color mode, resolution, etc.

      The fact that the preview is also updated when a preview request is explicitly called (orientation, page, scrolling, etc.) makes this even more unintuitive.

       

      This is a basic example that demonstrates the problem:

      from PyQt6.QtWidgets import *
      from PyQt6.QtPrintSupport import *

      class PrintPreview(QPrintPreviewDialog):
          def {}init{}(self):
              super().{}init{}()
              self.paintRequested.connect(self.makePreview)

          def makePreview(self, printer):
              print(
                  'Creating preview for "{}"\n'
                  'Color mode: {}\n'
                  'Resolutions: {}'
                  .format(
                      printer.printerName(), 
                      printer.colorMode(), 
                      ', '.join(map(str, printer.supportedResolutions()))
                  )
              )

      app = QApplication([])
      test = PrintPreview()
      test.open()
      app.exec()

       

      Steps to reproduce the problem:

      1. run the code having at least two printers with different capabilities (in this case, color mode and/or available resolutions);
      2. click the "Print" button;
      3. select a different printer;
      4. cancel the dialog;
      5. toggle landscape/portrait mode (to trigger the signal again);

      I understand that fixing this may be quite difficult, especially since the native dialog is used on Windows/macOS. Still, I believe that this inconsistent behavior should be addressed in some way: either a different signal could be created for actual printing, or, at least, the documentation should clarify this.

      PS: note that I selected the Qt versions I know are currently active, but this issue is actually common to any existing version, including future ones.

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            Unassigned Unassigned
            musicamante Maurizio Berti
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes