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

QPainterPath is drawn incorrectly when QPainter::Antialiasing is enabled

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: P2: Important P2: Important
    • 4.7.2
    • 4.7.0
    • GUI: Painting
    • None
    • Windows 7
    • 8ac7817f7a294428f4eda3c10f519e14fe9d71a0 718d22962de9b2798ccae4aac6cb5e3798d440a1 ea8dd9d2dbd3345fbf76625c441d9832f758bf70

      Occasionally, depending on the length of the text, the color of the text will be messed up.

      The problem doesn't appear when the text += "B"; line is removed and all the lines have the same length. It also doesn't reproduce when Antialiasing is not enabled on the QPainter.
      The issue doesn't appear on Linux both with the native and the raster engine.
      Also the drawing is much slower with 4.7.0 than with 4.6.3 or 4.5.3.

      Example reproducing the problem - the text starts off dark then, usually in the middle of a line, becomes lighter.
      #include <QtGui>
      
      static const int WIDTH = 750;
      static const int HEIGHT = 500;
      
      int main(int argc, char *argv[])
      {
      	QApplication a(argc, argv);
      	QFont font("Arial", 16);
      	int line = QFontMetrics(font).lineSpacing();
      	int y = line;
      	QString text = "B";
      	text = text.repeated(35);
      	QPainterPath painterPath;
      	while (y < HEIGHT)
      	{
      		text += "B";
      		painterPath.addText(QPointF(10, y), font, text);
      		y += line;
      	}
      
      	QImage image(WIDTH, HEIGHT, QImage::Format_ARGB32);
      	image.fill(Qt::transparent);
      
      	QPainter imagePainter(&image);
      	imagePainter.setRenderHints(QPainter::Antialiasing);
      	imagePainter.setOpacity(0.5);
      	imagePainter.setBrush(Qt::blue);
      	imagePainter.setPen(Qt::NoPen);
      	imagePainter.drawPath(painterPath);
      	imagePainter.end();
      
      	image.save("PaintTextPathTest.png","PNG");
      	
      	return 0;
      }
      

            rodal Samuel Rødal
            mpejcoch Martin Pejcoch (Inactive)
            Votes:
            1 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: