Change color to QPainterPath overlapping


I have a QPainterPath of a point path, which is the path of a machine. I draw that path with a QPainterPathStroke and up there all right. The problem is that this path could pass over itself, that is, overlap or maybe just touch it and in that case I would like to be able to paint that part of the overlay with another color. Can it be determined if a QPainterPath or QPainterPathStroke passes over itself ?. I leave the code of what I have:

QPainterPath path;

int i=1;
while (i + 2 < points.size()) {
    i += 3;
while (i < points.size()) {

QPainterPathStroker stroker;
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 the crossing is seen ... it is the same qpainterpath that at one time makes a kind of 8 and passes over itself

asked by Emiliano Torres 14.05.2018 в 02:59

1 answer


QColor allows you to set colors with some transparency. Just play with the%% share% of the color:

QColor(int r, int g, int b, int a = 255)
//                              ^

The effect when two colors with an alpha component other than 255 are superimposed will be a composition effect that is what you are looking for:

painter->fillPath(stroke, QColor(0,255,0, 128, 200));

Note that if the colors have transparency, their tone will be whiter (if the background is white) so you may have to also modify the RGB components so that the color is as expected.

answered by 14.05.2018 / 07:52