QCustomPlot的demo实例给的都是x轴和y轴 一起缩放的 用起来有点不方便。
下面实现的功能是,点击选中x轴 或者y轴 就能缩放;
下面是实现功能图:点击x轴 就能实现x轴的单独放大。
第一个方法是,改变缩放比例。
QCustomlot给我们提供了 setRangeZoomFactor()函数,设置区域放大因子,
ui->customPlot->axisRect()->setRangeZoomFactor(1.2,1);//x方向为1.2 y为1 是不改变。
第二个方法是,Qcustomplot 自己提供的函数设置办法。
setRangeZoom函数
源代码 (代码测试过 有效,)
void MainWindow::wheelEvent(QWheelEvent *event)
{ static int i=0;
i++;
if (ui->customPlot->xAxis->selectedParts().testFlag(QCPAxis::spAxis))
{
qDebug("%d",i);
ui->customPlot->axisRect()->setRangeZoom(ui->customPlot->xAxis->orientation());
// ui->customPlot->axisRect()->setRangeZoomFactor(1.2,1);//x方向为1.2
}
else if (ui->customPlot->yAxis->selectedParts().testFlag(QCPAxis::spAxis))
{
ui->customPlot->axisRect()->setRangeZoom(ui->customPlot->yAxis->orientation());
// ui->customPlot->axisRect()->setRangeZoomFactor(1.2,1);//x方向为1.2
}
else
ui->customPlot->axisRect()->setRangeZoom(Qt::Horizontal|Qt::Vertical);
}