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

Some pixels are missing when using drawPolygon() with a pen of size 1

    XMLWordPrintable

Details

    • Bug
    • Resolution: Out of scope
    • P2: Important
    • Some future release
    • 4.5.0
    • GUI: Painting
    • None

    Description

      On a pixmap, ::drawPolygon() with a pen of size 1 do not draw all pixels.

      For example, drawing a line with drawPolygon() is not the same as drawing with drawLine().

      Here is the test to reproduce the issue:

      #include <QtTest/QtTest>
      #include <QPainter>
      #include <QPixmap>

      class Test : public QObject{
      Q_OBJECT

      private slots:
      void testLineSize_data()

      { QTest::addColumn<int>("penSize"); QTest::newRow("0") << 0; QTest::newRow("1") << 1; }

      void testLineSize(){
      QPixmap pixmap(20, 1);
      pixmap.fill();
      QPainter painter(&pixmap);

      QPen pen(Qt::black);

      QFETCH(int, penSize);
      pen.setWidth(penSize);
      painter.setPen(pen);

      QPolygon polygon;
      polygon.putPoints(0, 2, 2, 0, 17, 0);
      painter.drawPolygon(polygon);
      // painter.drawLine(2, 0, 17, 0); < drawLine is Ok
      painter.end();

      QImage image = pixmap.toImage();
      int nb_pixels = 0;
      for(int i=0; i<20; ++i)

      { QRgb pixel = image.pixel(i, 0); if(pixel != QColor(Qt::white).rgb()) ++nb_pixels; }

      QCOMPARE(nb_pixels, 16);
      }
      };

      QTEST_MAIN(Test)
      #include "test.moc"

      Attachments

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

        Activity

          People

            rodal Samuel Rødal
            poulain Benjamin Poulain (closed Nokia identity) (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes