PDA

View Full Version : qwtplotdirectpainter don´t use penwidth of the curve



aker
6th September 2013, 10:35
Hello!

This is my first post to this forum. I usually allways find here a solution to my problem, but in this case I don´t...
I have an Application which uses qwt 6.1.0. I realized a real-time-plot based on the realtime and oscilloscope example. I have now 2 or more realtime curves in the plot and paint this to the canvas by QwtPlotDirectPainter.
One curve I want to display in different penwidth. The penwidth is working when I do a replot of the plot, but then I have a performance problem.
Can I set a penwidth so the directpainter paint the curve thicker??

Andre

Uwe
8th September 2013, 09:26
One curve I want to display in different penwidth. The penwidth is working when I do a replot of the plot, but then I have a performance problem.
Can I set a penwidth so the directpainter paint the curve thicker?
QwtPlotDirectPainter calls QwtPlotCurve::drawSeries(), where the curve pen is used for drawing the lines.
So setting a curve pen ( QwtPlotCurve::setPen() ) will affect the curve in the same way as with using replot().

Uwe

aker
9th September 2013, 07:37
Hello Uwe,

sorry but I can´t get it running. I set a pen to the curve with setPen() but only the color changes.
I tried it with my application and then with the oscilloscope example. Only when I do a replot() the pen uses the penWidth which I want to have.
This is the code from the example where I set a new pen.


d_curve = new QwtPlotCurve();
d_curve->setStyle( QwtPlotCurve::Lines );
// d_curve->setPen( canvas()->palette().color( QPalette::WindowText ) );
d_curve->setRenderHint( QwtPlotItem::RenderAntialiased, true );
d_curve->setPaintAttribute( QwtPlotCurve::ClipPolygons, false );
d_curve->setData( new CurveData() );
d_curve->attach( this );

QPen p;
p.setColor(Qt::red);
p.setWidthF(5);
d_curve->setPen(p);


and only when I do a replot after drawSeries() the line have a width of 5.



void Plot::updateCurve()
{
CurveData *data = static_cast<CurveData *>( d_curve->data() );
data->values().lock();

const int numPoints = data->size();
if ( numPoints > d_paintedPoints )
{
const bool doClip = !canvas()->testAttribute( Qt::WA_PaintOnScreen );
if ( doClip )
{
/*
Depending on the platform setting a clip might be an important
performance issue. F.e. for Qt Embedded this reduces the
part of the backing store that has to be copied out - maybe
to an unaccelerated frame buffer device.
*/

const QwtScaleMap xMap = canvasMap( d_curve->xAxis() );
const QwtScaleMap yMap = canvasMap( d_curve->yAxis() );

QRectF br = qwtBoundingRect( *data,
d_paintedPoints - 1, numPoints - 1 );

const QRect clipRect = QwtScaleMap::transform( xMap, yMap, br ).toRect();
d_directPainter->setClipRegion( clipRect );
}


d_directPainter->drawSeries( d_curve,
d_paintedPoints - 1, numPoints - 1 );

d_paintedPoints = numPoints;
}

data->values().unlock();

replot();
}



Can you tell me what I do wrong???

Andre

Uwe
9th September 2013, 08:43
...and only when I do a replot after drawSeries() the line have a width of 5.
The direct painter simply draws on top of the existing plot - nothing gets erased, what has been painted before.

If you want to apply a modified curve pen to replace parts of a curve, that you have painted before, you have to call replot - calling drawSeries() before is not necessary. There might be optimizations, when drawing with a thicker pen, but in general it is like this.

Uwe

aker
9th September 2013, 09:28
Hello Uwe,

yes you are right! I played around with some things and I also changed the data collection period. The penwidth is thicker but it looks not so smooth than after a complete replot.

Thank you Uwe!