-
Bug
-
Resolution: Done
-
P2: Important
-
4.3.4
-
None
The follow code reproduces shows the different results. The path drawing seems to be outside the frame points, but converting the path to a fill-polygon and drawing that renders it correctly again.
Re-tested and fault seen in Qt 4.5.1
Test case main.cpp to reproduce
===============================
#include <QtGui>
#include <math.h>
#ifndef PI
#define PI 3.1415927
#endif
class Shapes : public QWidget
{
Q_OBJECT
public:
Shapes()
{
}
protected:
void paintEvent(QPaintEvent *event)
{
int xOffset = 0;
int yOffset = 0;
const int shapeWidth = 55;
const int shapeHeight = 55;
const int padding = 2;
QPainter painter(this);
painter.translate(padding, padding);
QPen framePen(Qt::lightGray, 1);
QPen shapePen(Qt::black, 1);
QBrush fillBrush(Qt::red);
for (int shape = 0; shape < 6; ++shape) {
painter.setPen(framePen);
painter.drawRect(0, 0, shapeWidth, shapeHeight);
painter.setPen(shapePen);
switch (shape)
{
case 0:
break;
case 1:
painter.drawLine(0, 0, shapeWidth, shapeHeight);
painter.drawLine(0, shapeHeight, shapeWidth, 0);
break;
case 2:
case 3:
case 4:
case 5:
{
painter.translate(shapeWidth / 2.0, shapeHeight / 2.0);
QPoint points[8];
int p = 0;
for (double i = 0; p < 8; ++p, i += (PI*3.0 / 4.0))
if (shape == 2)
{ painter.drawPolygon(points, 8); } else {
QPainterPath path;
path.setFillRule(Qt::WindingFill);
path.moveTo(points[0]);
for (int p = 1; p < 8; ++p)
path.lineTo(points[0]);
switch (shape) {
case 3:
painter.setBrush(fillBrush);
case 4:
painter.drawPath(path);
painter.setBrush(Qt::NoBrush);
break;
case 5:
}
}
painter.translate(-shapeWidth / 2.0, -shapeHeight / 2.0);
}
break;
}
if (xOffset + shapeWidth + padding > width())
{ painter.translate(-xOffset, shapeHeight + padding); yOffset += shapeHeight + padding; }else
{ painter.translate(shapeWidth + padding, 0); xOffset += shapeWidth + padding; } }
}
};
#include "main.moc"
int main (int argc, char **argv)
{
QApplication app(argc, argv);
Shapes shapes;
shapes.show();
return app.exec();
}
======================================
Update: rescheduled to some future release. The difference in behavior is because we use Bresenham for drawing lines and polygon outlines, whereas for path outlines we generate an outline path using the stroker which we then rasterize as a generic path.