So the (other) final solution is:
Draw along outline points of shape:
qt-quest1.1.jpg
stroker.setCapStyle(Qt::RoundCap);
stroker.setJoinStyle(Qt::RoundJoin);
stroker.setWidth(100);
QPainterPath strokePath
= stroker.
createStroke(path
).
simplified();
for (int i = 0; i < strokePath.elementCount()-1; i++)
{
painter
->setPen
(QPen(i
% 2 == 0 ? Qt
::red : Qt
::green,
1));
}
QPainterPath path(QPointF(80, 320));
path.lineTo(QPointF(240,90));
path.lineTo(QPointF(330,240));
path.lineTo(QPointF(620,180));
path.lineTo(QPointF(730,110));
QPainterPathStroker stroker;
stroker.setCapStyle(Qt::RoundCap);
stroker.setJoinStyle(Qt::RoundJoin);
stroker.setWidth(100);
QPainterPath strokePath = stroker.createStroke(path).simplified();
for (int i = 0; i < strokePath.elementCount()-1; i++)
{
QPainterPath::Element p1 = strokePath.elementAt(i);
QPainterPath::Element p2 = strokePath.elementAt(i+1);
painter->setPen(QPen(i % 2 == 0 ? Qt::red : Qt::green, 1));
painter->drawLine(QPointF(p1.x, p1.y), QPointF(p2.x, p2.y));
}
To copy to clipboard, switch view to plain text mode
Solved.
Bookmarks