koan
10th October 2010, 15:52
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.
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);
}
5299
Note: The image in the preview for this post doesn't look right: click through to see the attachment properly
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.
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);
}
5299
Note: The image in the preview for this post doesn't look right: click through to see the attachment properly