QwtPlot how to save/restore zoom settings
Hello, I use QwtPlot with one QwtPlotCurve, xBotton, yRight axes; I would like to save and restore the plot's zoom settings (when user exist/when user restarts the program). The idea is to get the user back to the same looking plot. Can anyone point me in the right direction?
Re: QwtPlot how to save/restore zoom settings
Store the x and y extents in member variables of whatever widget holds your plot, and use QSettings as a way to store them persistently on disk. Override the widget's showEvent() and closeEvent() methods. In showEvent(), read the settings in and set the zoom extents. In closeEvent(), save the settings.
If the current zoom extents are accessible from QwtPlot, then you may not need the member variables. Just read or write them directly from the plot on load and save.
Re: QwtPlot how to save/restore zoom settings
Thanks for the response.
I looked through all relevant classes APIs starting with QwtPlot, I just can't find the API to get/set zoom extents.. (starting point/ending value for each x/y axis or equivalent data)
Re: QwtPlot how to save/restore zoom settings
A solution that worked for me was saving "zoomRect" and then restoring using "setZoomRect"
Code:
{
QRectF rect
= QRectF( xs.
lowerBound(), ys.
lowerBound(), xs.
range(), ys.
range() );
return rect;
}
void setZoomRect(const QRectF& r)
{
d->zoomer->zoom(r);
}
Re: QwtPlot how to save/restore zoom settings
You don't need a zoomer to set the scale intervals - simply use setAxisScale or setAxisScaleDiv.
Uwe
Re: QwtPlot how to save/restore zoom settings
Thanks Uwe.
now using:
Code:
{
return QRectF( xs.
lowerBound(), ys.
lowerBound(), xs.
range(), ys.
range() );
}
void CGraph::setZoomRect(const QRectF& r)
{
this
->setAxisScale
(QwtPlot::xBottom, r.
left(), r.
right());
this
->setAxisScale
(QwtPlot::yLeft, r.
top(), r.
bottom());
}