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

QPainter leaves some pixels transparent when painting with an image-based QBrush

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • P3: Somewhat important
    • 5.9.2
    • 5.9.1
    • GUI: Painting
    • None
    • Mac OS 10.12.5

    Description

      If I use a QPainter to paint a QImage target, using an image-based QBrush, and the painter's target allows transparency, the result will have some pixels arbitrarily fully transparent even though the QPainter's QBrush did not include any transparent pixels. This seems to have started happening recently; it didn't happen back on 5.7 and earlier.

      For example, this simple code should save an image with all magenta pixels, but ends up having a line of fully transparent pixels near column ~5400:

      #include <QCoreApplication>
      #include <QPainter>
      #include <QRectF>
      #include <QBrush>
      #include <QColor>
      #include <QImage>
      #include <QTransform>
      
      int main(int argc, char *argv[])
      {
       QImage im(6000, 6000, QImage::Format_ARGB32);
       QImage brushIm(522, 546, QImage::Format_ARGB32);
       brushIm.fill(QColor(255,0,255));
       QBrush brush(brushIm);
       brush.setTransform(QTransform::fromScale(0.626419669526,0.626419669526));
       QPainter painter(&im);
       painter.setRenderHint(QPainter::SmoothPixmapTransform, true);
       painter.setBrush(brush);
       QRectF rect(0, 0, 6000, 6000);
       QPainterPath path;
       path.addRect(rect);
       painter.drawPath(path);
       painter.end();
       im.save("test.png");
      }
      

      I've attached the bad image it generates for me w/ the column of fully transparent pixels.

      If I do not set `QPainter::SmoothPixmapTransform` then the issue does not happen.
      If I pick a QImage format that does not allow transparency (Format_RGB32) then the issue does not happen.

      Attachments

        1. repro.cc
          0.7 kB
        2. test.png
          test.png
          149 kB
        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            allan.jensen Allan Sandfeld Jensen
            zaphos James Andrews
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes