I want to draw some triangles in my widget pointing up: ie. two vertices are on the same horizontal line and a third vertex halfway between these two points and above.
When the triangle is not filled the top vertex is "sharp" but when I draw the triangle filled, it does not have a "sharp" point: an extra diagonal line of pixels is added on the left side, outside of the triangle.
{
p.setPen(Qt::black);
p.setBrush(Qt::black);
int halfwidth = 7;
int height = 7;
triangle.clear();
triangle <<
QPoint(10+halfwidth,
10-height
);
triangle <<
QPoint(10+2*halfwidth,
10);
p.drawPolygon(triangle);
}
void widget::paintEvent(QPaintEvent *)
{
QPainter p(this);
p.setPen(Qt::black);
p.setBrush(Qt::black);
int halfwidth = 7;
int height = 7;
QPolygon triangle;
triangle.clear();
triangle << QPoint(10+halfwidth, 10-height);
triangle << QPoint(10, 10);
triangle << QPoint(10+2*halfwidth, 10);
p.drawPolygon(triangle);
}
To copy to clipboard, switch view to plain text mode
unfill-vs-fill-zoom.png
Note: The image in the preview for this post doesn't look right: click through to see the attachment properly
Bookmarks