Assuming that you have new curve points in the area [x1,x2] ( in plot coordinates ) and the backingstore ( QwtPlotCanvas::BackingStore ) of the canvas is disabled:
void updatePlot
( QwtPlot* plot,
double x1,
double x2
) {
const int l = xMap.transform( x1 );
const int r = xMap.transform( x2 );
const QRect cr
= plot
->canvas
()->contentsRect
();
plot->canvas()->repaint( l, cr.y(), r - l, cr,height() );
}
void updatePlot( QwtPlot* plot, double x1, double x2 )
{
const QwtScaleMap xMap = plot->canvasMap( QwtPlot::xBottom );
const int l = xMap.transform( x1 );
const int r = xMap.transform( x2 );
const QRect cr = plot->canvas()->contentsRect();
plot->canvas()->repaint( l, cr.y(), r - l, cr,height() );
}
To copy to clipboard, switch view to plain text mode
The rectangle you have passed to the paint event will end up as clip region of the painter and you could overload QwtPlot::drawItems():
virtual void YourPlot
::drawItems( QPainter *painter,
const QRectF &canvasRect,
{
const QRectF rect
= painter
->clipRegion
().
boundingRect();
// rect should have been filled with the background of the canvas
// before. When you have other plot items ( f.e. a grid ) you have to restore
// them for rect() too.
...
double x1 = maps[curve->xAxis()].invTransform( rect.x() );
double x2 = maps[curve->xAxis()].invTransform( rect.x() + rect.width() );
// find the segment of your curve for [x1, x2]
// f.e. using qwtUpperSampleIndex() ?
int from = ...;
int to = ...
curve->drawSeries( painter,
maps[curve->xAxis()], maps[curve->yAxis()], canvasRect, from, to );
}
virtual void YourPlot::drawItems( QPainter *painter, const QRectF &canvasRect,
const QwtScaleMap maps[axisCnt] ) const
{
const QRectF rect = painter->clipRegion().boundingRect();
// rect should have been filled with the background of the canvas
// before. When you have other plot items ( f.e. a grid ) you have to restore
// them for rect() too.
...
double x1 = maps[curve->xAxis()].invTransform( rect.x() );
double x2 = maps[curve->xAxis()].invTransform( rect.x() + rect.width() );
// find the segment of your curve for [x1, x2]
// f.e. using qwtUpperSampleIndex() ?
int from = ...;
int to = ...
curve->drawSeries( painter,
maps[curve->xAxis()], maps[curve->yAxis()], canvasRect, from, to );
}
To copy to clipboard, switch view to plain text mode
You could try to use QwtPlotGLCanvas, that offers hardware acceleration and its limitations should be no big issue for your type of application. For QwtPlotCanvas ( = anything derived from QWidget ) there is only Qt4/X11 ( native graphicssystem ) where you have hardware acceleration.
Uwe
Bookmarks