Change color to QPainterPath overlapping

1

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;
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 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
source

1 answer

2

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
source