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

QImage drawEllipse bug

    XMLWordPrintable

Details

    • Bug
    • Resolution: Out of scope
    • P2: Important
    • Some future release
    • 4.3.2, 4.5.3, 4.6.0
    • GUI: Painting
    • None

    Description

      I would have expected the red ellipse to completely cover the white ellipse.

      This does not seem to be the case. One can see a little bit of the white ellipse.

      #include <QtGui>
      
      int main(int argc, char *argv[])
      {
          QApplication app(argc, argv);
          QImage im(500, 500, QImage::Format_ARGB32_Premultiplied);
          im.fill(QColor(Qt::blue).rgba());
          QPainter p(&im);
          QPen pen1;
          pen1.setStyle(Qt::DashLine);
          pen1.setColor(Qt::white);
          pen1.setCapStyle(Qt::FlatCap);
          QPen pen2;
          pen2.setStyle(Qt::SolidLine);
          pen2.setColor(Qt::red);
          QPen *pens[] = { &pen1, &pen2, 0 };
          for (int i=0; pens[i]; ++i) {
              pens[i]->setWidthF(150);
              p.setPen(*pens[i]);
              p.drawEllipse(100, 100, 300, 300);
          }
          QLabel lbl;
          lbl.setPixmap(QPixmap::fromImage(im));
          lbl.show();
          return app.exec();
      }
      

      Update: as a workaround for this you can use the QPainterPathStroker and setCurveThreshold with a low value (0.0001 or so).

      Another workaround is to convert the ellipse to a polygon using QPainterPath::addEllipse and QPainterPath::toFillPolygon, and then draw the polygon instead. This avoids some of the inaccuracies in the curve stroker and should give overlapping outlines with different pen styles.

      Attachments

        Issue Links

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

          Activity

            People

              rodal Samuel Rødal
              rve Anders Bakken
              Votes:
              1 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes