PDA

View Full Version : How to use QPainterPathStroker?



lni
12th August 2011, 11:52
Hi,

I need to create an outline following a curve with a fixed width (said 100), as shown in my attachment 1.

To do this, I use QPainterPathStroker using following code. However, the resulting stroker joins them with the curve (see attachment 2). What I want is the outline without joining with the curve. How can I do so? Thanks!




QVector<QPointF> myCurve; // <-- myCurve is calculated somewhere else.

QPainterPath curvePath;
curvePath.moveTo( myCurve[ 0 ] );
for ( int idx = 1; idx < myCurve.size(); idx++ ) {
curvePath.lineTo( myCurve[ idx ] );
}

QPainterPathStroker stroker;
stroker.setCapStyle( Qt::RoundCap );
stroker.setJoinStyle( Qt::RoundJoin );
stroker.setWidth( 100 );
QPainterPath outline = stroker.createStroke ( curvePath );
painter->drawPath( outline );

lni
13th August 2011, 14:48
Anyone please?

d_stranz
14th August 2011, 18:22
Do you set a fill brush for your painter before drawing the path? Do you set the pen to "NoPen"?

lni
15th August 2011, 05:58
Do you set a fill brush for your painter before drawing the path? Do you set the pen to "NoPen"?

The problem is not pen or brush, it is problem that it connects the stroking path with the input curve path, causing error in my other computation. What I need is the outline without connecting to the center red curve.