I have a QPainterPath of a path of points, which is the path of a machine. I draw that path with a QPainterPathStroke and so far so good. The problem is that this path could pass over itself, that is, overlap or perhaps just brush it, and in that case I would like to be able to paint that part of the overlap with another color. Can you determine if a QPainterPath or QPainterPathStroke passes over itself? I leave you the code of what I have:
QPainterPath path;
path.moveTo(points.at(0));
int i=1;
while (i + 2 < points.size()) {
path.cubicTo(points.at(i), points.at(i+1), points.at(i+2));
i += 3;
}
while (i < points.size()) {
path.lineTo(points.at(i));
++i;
}
QPainterPathStroker stroker;
stroker.setWidth(24);
QPainterPath stroke = stroker.createStroke(path);
painter->fillPath(stroke, QColor(0,255,0, 128));
points is a QVector. The width of the painterpathstroke is 24 because that is the width of the machine.
Here I upload an image, where you can see the crossing... it's the same qpainterpath that at one point does a kind of 8 and passes over itself
QColor
allows you to set colors with some transparency. Just play with thea
color part:The effect when two colors with an alpha component other than 255 overlap will be a composition effect, which is what you are looking for:
Note that if the colors have transparency their tone will be more whitish (if the background is white) so you may have to modify the RGB components as well to make the color as you expect.