If you don't want to implement the filling algo yourself ( setting pixels on a QImage ) using clip rects is not a bad idea.
Assuming you already have created a polygon ( clipped to the canvas rectangle ) with the outline of both points in paint device coordinates and your list of crossing points is also clipped, so that all points outside the canvas rectangle are not included:
Then all that needs to be done in your loop is:
double y1 = canvasRect.y();
for ( int i = 0; i < crossingNum; i++ )
{
const double y2 = yMap.transform( crossingPoint[i].y() );
painter->setClipRect( canvasRect.x(), y1, canvasRect.width(), y2 - y1 );
painter->setBrush( ... );
painter->drawPolygon( ... );
y1 = y2;
}
painter->setClipRect( canvasRect.x(), y1, canvasRect.width(), canvasRect.bottom() - y1 );
painter->setBrush( ... );
painter->drawPolygon( ... );
double y1 = canvasRect.y();
for ( int i = 0; i < crossingNum; i++ )
{
const double y2 = yMap.transform( crossingPoint[i].y() );
painter->setClipRect( canvasRect.x(), y1, canvasRect.width(), y2 - y1 );
painter->setBrush( ... );
painter->drawPolygon( ... );
y1 = y2;
}
painter->setClipRect( canvasRect.x(), y1, canvasRect.width(), canvasRect.bottom() - y1 );
painter->setBrush( ... );
painter->drawPolygon( ... );
To copy to clipboard, switch view to plain text mode
Qt is known for rendering before clipping, so it's worth to try to clip the polygon with QwtClipper against the current clip rectangle, before calling QPainter::drawPolygon. If this results in a significant better performance you could consider to implement a faster clipping algo instead of Sutherland-Hodgman using the fact, that your points are ordered in vertical direction.
Uwe
Bookmarks