두 펜 대신 펜과 브러시를 사용하지만 QPainterPath
을 사용할 수 있습니다. 작업을 수행하는 예제 함수를 불어 넣으십시오.
void drawLineWithBorder(QPainter& pt, const QPoint& p0, const QPoint& p1,
const QPen& borderPen, const QBrush& lineBrush, float width)
{
// Line vectors
QPointF v1(p1 - p0);
v1 /= sqrt(v1.x() * v1.x() + v1.y() * v1.y()); // normalized it
v1 *= width; // line thickness
QPoint v2(v1.y(), -v1.x()); // line rotated 90 degrees
// Draw a rotated rectangle to generate a 'line with borders'
// It needs to be closed in order to paint the inner region
QPainterPath path;
path.moveTo(p0);
path.lineTo(p1);
path.lineTo(p1 + v2);
path.lineTo(p1 + v2 - v1);
path.lineTo(p0);
pt.save(); // save current state of the painter
pt.setPen(borderPen);
pt.setBrush(lineBrush);
pt.drawPath(path);
pt.restore();
}
반면에 두 개의 평행선이 필요하면 두 가지 선을 그려야합니다.
긴 직사각형 ... – CapelliC
다각형은 어떨까요? –