PDA

View Full Version : QPainterPath add subPath in foreground



GuillaumeG
19th March 2015, 09:15
Hi,

I use QPainterPath to draw a line. I want to add a polygon in front of the line with addPolygon to draw an arrow head.
But the polygon is in background, and the line is always shown in front of the arrow head.

Here my code :



QPainterPath myPath;
myPath.moveTo( xo,yo);
myPath.lineTo( x, y );
...
QPolygonF arrowHead;
arrowHead << p << arrowP1 << arrowP2;
myPath.addPolygon(arrowHead);
myPath.closeSubpath();


I use QPainterPath::addEllipse too, to make disk arrow head, and I have the same problem.

What is the solution to move subpath in foreground ?

d_stranz
19th March 2015, 15:55
If you aren't specifying a brush when you draw your path, the the polygon is not being filled, and that's why the line is visible. It has nothing to do with foreground / background. All of the items in the path are at the same Z-level. If you don't want the end of the line to be visible, then calculate its endpoints correctly so it ends at the polygon border, not inside it.

Kryzon
19th March 2015, 22:04
It's possible that QPainter first fills the path with the brush and then draws all the strokes afterwards, with the pen. So the line would always be displayed on top.

As an alternative to setting the line endpoint to the edge of the arrow, you can try using two different QPainterPaths -- then you have absolute control over the rendering order.