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

Ghost lines and incorrect colors while using a QPrinter with OutputFormat set to PdfFormat

    XMLWordPrintable

Details

    • Bug
    • Resolution: Out of scope
    • Not Evaluated
    • None
    • 4.8.0
    • None
    • Windows 7 + Visual Studio 2010

    Description

      Hi.

      I have been trying to print to pdf with incorrect results.

      Expected behavior

      Using the combination of a PdfFormat on a QPrinter, a linear gradient and a scale to draw a rectangle (NoPen) should draw a gradient only, using the right colors.

      What happens

      Without anti-aliasing, lines appear on the top and left corners of the rectangle.
      Activating anti-aliasing seems to fix the lines problem but creates a new one where colors becomes dirty in adobe reader (but fine with any other pdf reader). I suspect to bug to be linked to the first one, but may be a separate one.

      Minimal code reproducing the problem

      (try false/true for setRenderHints(QPainter::Antialiasing, ...) to get different results)

      #include <QPainter>
      #include <QPrinter>
      #include <QtCore/QCoreApplication>
      
      int main(int argc, char *argv[])
      {
      	QCoreApplication a(argc, argv);
      
      	QPrinter* printer = new QPrinter();
      	printer->setOutputFileName("print.pdf");
      	printer->setOutputFormat(QPrinter::PdfFormat);
      
      	QPainter painter(printer);
      	painter.setRenderHints(QPainter::Antialiasing, false);
      	painter.setPen(Qt::NoPen);
      
      	QLinearGradient grad(0.0f, 0.0f, 0.0f, 90.0f);
      	grad.setColorAt(0.0f, Qt::blue);
      	grad.setColorAt(1.0f, Qt::white);
      
      	painter.setBrush(grad);
      	painter.scale(1.337, 1.337);
      	painter.drawRect(QRect(10, 10, 100, 100));
      	painter.end();
      
      	return 0;
      }
      

      Attachment

      Screenshot showing on the:

      • left-top: Adobe Reader with Antialiasing to false
      • left-right: Adobe Reader with Antialiasing to true
      • bottom: Foxit Reader with Antialiasing to true
        Lines still appear on Foxit Reader with Antialiasing to false.

      Attachments

        1. main.cpp
          0.7 kB
        2. qt-linescolor.png
          qt-linescolor.png
          225 kB

        Issue Links

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

          Activity

            People

              Unassigned Unassigned
              wiz Clément Léger
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes