Got the dynamic re-scaling working ok now with Uwe's help.
const double center = (scaleDiv.lowerBound() + scaleDiv.range() / 2) + diff * 2;
const double width_2 = scaleDiv.range() / 2 ;
QwtPlot::setAxisScale(QwtPlot::xTop, center
- width_2, center
+ width_2,
10000);
setAxisScaleDraw
(QwtPlot::xTop,
new NewScaleDraw
());
replot();
const QwtScaleDiv &scaleDiv = axisScaleDiv(QwtPlot::xTop);
const double center = (scaleDiv.lowerBound() + scaleDiv.range() / 2) + diff * 2;
const double width_2 = scaleDiv.range() / 2 ;
QwtPlot::setAxisScale(QwtPlot::xTop, center - width_2, center + width_2, 10000);
setAxisScaleDraw(QwtPlot::xTop, new NewScaleDraw());
replot();
To copy to clipboard, switch view to plain text mode
Scale shows as 10 major divisions with 4 minor divisions - good so far.
But, the grid has 6 major divisions with 3 minor divisions - not so good. Need it to line up with the scale.
Here is how the grid was created
grid->enableX(true);
grid->enableY(true);
grid->enableXMin(true);
grid->enableYMin(false);
majPen->setWidth(1);
majPen->setStyle(Qt::SolidLine);
majColor.setNamedColor("white");
majPen->setColor(majColor);
minPen->setWidth(1);
minPen->setStyle(Qt::DotLine);
minColor.setNamedColor("grey");
minPen->setColor(minColor);
grid->setMajorPen(*majPen);
grid->setMinorPen(*minPen);
grid->attach(this);
QwtPlotGrid *grid = new QwtPlotGrid;
grid->enableX(true);
grid->enableY(true);
grid->enableXMin(true);
grid->enableYMin(false);
QPen* majPen = new QPen;
majPen->setWidth(1);
majPen->setStyle(Qt::SolidLine);
QColor majColor;
majColor.setNamedColor("white");
majPen->setColor(majColor);
QPen* minPen = new QPen;
minPen->setWidth(1);
minPen->setStyle(Qt::DotLine);
QColor minColor;
minColor.setNamedColor("grey");
minPen->setColor(minColor);
grid->setMajorPen(*majPen);
grid->setMinorPen(*minPen);
grid->attach(this);
To copy to clipboard, switch view to plain text mode
So what am I doing wrong that the grid doesn't line up with the scale?
Thanks for any assistance.
Bookmarks