QCustomPlot Discussion and Comments

Drag/scalearound zeroReturn to overview

Hello all,

What is the recommended way to make dragging scale the graph (vertically) around zero? I have graphs which contain positive and negative values, and the normal drag-scale extends the graph while keeping the minimum value at the bottom of the rectangle; I would like to change this so that it will keep the zero values (i.e., the horizontal axis) at the same vertical position and change the scale factor around that.

Should I calculate and re-apply the range in rangeChanged()?

you should be able to disable scaling in the x axis using
plot->axisRect()->setRangeZoomAxes(nullptr,plot->yaxis);

Sander, I'm not sure I fully understand what you mean.

In any case, limiting the behaviour of the range dragging and zooming is a typical use-case of the rangeChanged signal. So indeed, you can connect a slot to rangeChanged, and in the slot, use the passed QCPRange (which is the new range), modify it, and set a corrected range with setRange.