PDA

View Full Version : recalculate lables in QwtScaleDraw



tavla
31st October 2013, 10:24
hello.

I have a source of data that is displayed in real time. the x-axis is current coordinate and it varies randomly (depending on the speed and direction). so for chart on the x-axis I'm using the current number of points, and replace it when displayed on the coordinate in QwtScaleDraw:


// in QwtPlotCurve *pcd I fill data:
for (int i = 0; (i < data.length); i++){
xAlias[i] = i;
x[i] = data_x[i];
y[i] = data_y[i];
}
setSamples(xAlias, y, data.length);

// in QwtScaleDraw I take real value by alias:
QwtText myQwtScaleDraw::label(double v) const
{
return QString("%1").arg(pcd->x[((int)v)]);
}

// in main Widget:
myPlot->setAxisScale(QwtPlot::xBottom, 0, data.length, 0);
myPlot->replot();


but this only works if there is a change of xAlias[]. if I change the array x referenced by the xAlias, repainting occurs.
how to make a graph to be redrawn manually?
myPlot->repaint(), myPlot->update(), myPlot->axisWidget( QwtPlot::xBottom )->update(); does not work too.

Thanks in advance.

tavla
1st November 2013, 12:51
I found the solution:

((myQwtScaleDraw*)myPlot->axisScaleDraw(QwtPlot::xBottom))->invalidate(); // protected invalidateCache() inside;
myPlot->update();
myPlot->replot();
might be useful to someone