Just for the record, I have been able to solve this problem using a dash pattern. Following is an example code, where dLength is the amount of the painterPath we want to draw:
QPen painterPen
(painter
->pen
());
QVector<qreal> dashes;
// The first element of the vector is the length we want to draw
// We must divide it by the width of the pen because
// the dash painting works with pen units.
// The second element is the empty part of the path - setting it
// to the length of the path ensures the dash pattern won't repeat.
dashes << dLength / pen.width() << painterPath.length();
pen.setDashPattern(dashes);
painter->setPen(pen);
painter->drawPath(painterPath);
painter->setPen(painterPen);
QPen painterPen(painter->pen());
QPen pen(painterPen);
QVector<qreal> dashes;
// The first element of the vector is the length we want to draw
// We must divide it by the width of the pen because
// the dash painting works with pen units.
// The second element is the empty part of the path - setting it
// to the length of the path ensures the dash pattern won't repeat.
dashes << dLength / pen.width() << painterPath.length();
pen.setDashPattern(dashes);
painter->setPen(pen);
painter->drawPath(painterPath);
painter->setPen(painterPen);
To copy to clipboard, switch view to plain text mode
It works good and fast. And of course, it is possible to draw from the middle of the path by using 4 values in the vector instead of 2.
Bookmarks