QCustomPlot Discussion and Comments

How to stay in a certain rangeReturn to overview

I will zoom and drag the range, but I need it to stay at a certain range like [-90,90], how can I make it? Thank you so much!

connect the rangeChanged signal to a slot. The slot is as below:

void onRangeChanged(QCPRange range)
{
if (range.lower < -90 && range.upper < 90) {
auto offset = -90 - range.lower;
QCPRange cpRange(-90, range.upper + offset);
range = cpRange;
} else if (range.lower > -90 && range.upper > 90) {
auto offset = range.upper - 90;
QCPRange cpRange(range.lower - offset, 90);
range = cpRange;
} else if (range.lower >= -90 && range.upper <= 90) {
QCPRange cpRange(range.lower, range.upper);
range = cpRange;
} else {
QCPRange cpRange(-90, 90);
range = cpRange;
}
setXRange(range);
//replot
}