PDA

View Full Version : Understanding QPainterPath::simplified()



Kryzon
1st November 2014, 09:51
Hello.
My implementation of 'paintEvent' is giving a particular result:


void Widget::paintEvent( QPaintEvent * event )
{
QPainter p ( this );
p.setPen( QPen( QBrush( Qt::darkRed ), 2 ) );
p.setBrush( QBrush( Qt::gray ) );

QPainterPath myPath;
myPath.moveTo( 600.0, 250.0 );
myPath.cubicTo( 90.0, 50.0, 0.0, 50.0, 50.0, 370.0 );
myPath.cubicTo( 140.0, 20.0, 10.0, 10.0, 600.0, 250.0 );

myPath.addRect( 10.0, 300.0, 160.0, 34.0 );

QPainterPath result ( myPath.simplified() );
p.drawPath( result );
}

Looking like this:
http://s7.postimg.org/3s67tyfwb/painter_Path.png

Shouldn't the intersected region between the rectangle and the bezier path be filled in the path generated by the 'simplified' call?

wysota
2nd November 2014, 10:56
What fill mode do you have set on the path?

Kryzon
10th November 2014, 10:10
Hello.
I'm using WindingFill, but in any case I tested with either of the fill modes and the result is the same.

According to some more research, QPainterPath::simplified will output a path that looks the same as the original when painted.
So for "moveTo" elements like that rectangle I can create a temporary path and then unite both as a boolean operation.
Additionally, QPainterPath::simplified will convert that path which originally has 7 elements into a 145 "lineTo" elements path that is an approximation, so it won't work for what I want.

This is the result from QPainterPath::simplified:
http://s15.postimg.org/gp8t6acnv/painter_Path2.png

I'll try something with a computational geometry library, and then feed the results back to Qt for rendering.