QCustomPlot Discussion and Comments

Scroll wheel zoom limit - how to prevent zooming too muchReturn to overview

I am using QCP to display an optical image as a QCPItemPixmap with a colormap overlayed on top of it.

I am making sure the image cannot be zoomed/dragged out further than the bounding box using QCPRange::bounded function. I do this using the beforeReplot() signal (the rangeChanged(QCPRange) required twice as much replotting because of both axes). Simply:

plot->xAxis->setRange(plot->xAxis->range().bounded(overlay_plot_min_range, overlay_plot_max_range));
plot->yAxis->setRange(plot->yAxis->range().bounded(overlay_plot_min_range, overlay_plot_max_range));

This is the only "custom code" I use for the zooming feature, I let the built in drag/zoom interactions do everything else.

One issue I am having is that when zooming in to the picture quite a lot, it eventually disappears and shows my existing background gradient, and I get the following in my Application Output pane:

QImage: out of memory, returning null.

Is there a way I can limit the amount of zoom using the scroll wheel?

Cheers

void QCPAxisRect::wheelEvent(QWheelEvent *event)
{
// Mouse range zooming interaction:
if (mParentPlot->interactions().testFlag(QCP::iRangeZoom))
{
if (mRangeZoom != 0)
{
double factor;
double wheelSteps = event->delta()/120.0; // a single step delta is +/-120 usually

if (mZoomFactorLimit)
{
if (mZoomFactor + wheelSteps <= mMinZoomFactorLimit ||
mZoomFactor + wheelSteps >= mMaxZoomFactorLimit)
{
return;
}
mZoomFactor += wheelSteps;
}

if (mRangeZoom.testFlag(Qt::Horizontal))
{
factor = qPow(mRangeZoomFactorHorz, wheelSteps);
for (int i=0; i<mRangeZoomHorzAxis.size(); ++i)
{
if (!mRangeZoomHorzAxis.at(i).isNull())
mRangeZoomHorzAxis.at(i)->scaleRange(factor, mRangeZoomHorzAxis.at(i)->pixelToCoord(event->pos().x()), mZoomType);
}
}
if (mRangeZoom.testFlag(Qt::Vertical))
{
factor = qPow(mRangeZoomFactorVert, wheelSteps);
for (int i=0; i<mRangeZoomVertAxis.size(); ++i)
{
if (!mRangeZoomVertAxis.at(i).isNull())
mRangeZoomVertAxis.at(i)->scaleRange(factor, mRangeZoomVertAxis.at(i)->pixelToCoord(event->pos().y()), mZoomType);
}
}
mParentPlot->replot();
}
}
}