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

QWidget::render to QPrinter of PDF type rasterizes text

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Reported
    • Priority: P3: Somewhat important
    • Resolution: Unresolved
    • Affects Version/s: 5.15.0
    • Fix Version/s: None
    • Component/s: GUI: Printing
    • Labels:
      None
    • Platform/s:
      Linux/X11

      Description

      I want to export the contents of a widget to either PDF or SVG and add a title.

      For exporting to SVG, I use QSvgRenderer, and for PDF, I consider QPrinter and QPdfWriter.

      For SVG everything works fine. But when using QPrinter as the QPaintDevice, the widget text gets rasterized even though the added title gets correctly exported as scalable text! I don't understand why this would happen.

      When using QPdfWriter as a possible workaround, the added title text is much larger than rendered widget text, which makes no sense and is completely inconsistent to all other behaviors. I'm lost here. Should I open a different issue for the QPdfWriter problem?

      A minimal example is attached. QPrinter can be swapped for QPdfWriter using the defined macros. I also tried to render directly to a paint device but it doesn't seem to matter and also does not seem to work when I want to add a title. Exporting to svg or pdf gets triggered when pressing the s key.

      main.cpp project.pro

      SVG as rendered using a QPainter to QSvgRenderer (the screenshot is still from an old version using blue instead of magenta):

      test.svg

      PDF as rendered using a QPainter to QPrinter (the text in the center is rasterized but not the title):

      test.pdf

      PDF as rendered using QPainter to QPdfWriter (the centered text is much smaller than the title text but nor rasterized. Also there is a white line at the bottom hinting to some weird rounding error!):

      test-qpdfwriter.pdf

      ^^

      ^As for the size difference. My guess is that the default DPI is for some reason a different one in printer vs. pdfwriter?^

        Attachments

        1. main.cpp
          3 kB
        2. project.pro
          0.1 kB
        3. Screenshot_2020-07-08_15-06-14.png
          Screenshot_2020-07-08_15-06-14.png
          4 kB
        4. Screenshot_2020-07-08_15-16-29.png
          Screenshot_2020-07-08_15-16-29.png
          57 kB
        5. Selection_438.png
          Selection_438.png
          23 kB
        6. test.pdf
          15 kB
        7. test.svg
          2 kB
        8. test-qpdfwriter.pdf
          8 kB
        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

            Assignee:
            johnlayt John Layt
            Reporter:
            uiohbgq uiohbgq
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Dates

              Created:
              Updated:

                Gerrit Reviews

                There are no open Gerrit changes