您可以通过选择要缩放的轴并添加 mouseWheel 插槽来仅缩放一个轴。
将鼠标滚轮信号连接到您的插槽:
connect(my_w.plot, SIGNAL(mouseWheel(QWheelEvent*)), this, SLOT(mouseWheel()));
实现鼠标滚轮插槽:
void YourDialog::mouseWheel()
{
// if an axis is selected, only allow the direction of that axis to be zoomed
// if no axis is selected, both directions may be zoomed
if (my_w.plot->xAxis->selectedParts().testFlag(QCPAxis::spAxis)){
my_w.plot->axisRect()->setRangeZoomAxes(my_w.plot->xAxis,my_w.plot->yAxis);
my_w.plot->axisRect()->setRangeZoom(my_w.plot->xAxis->orientation());
}
else if (my_w.plot->yAxis->selectedParts().testFlag(QCPAxis::spAxis)){
my_w.plot->axisRect()->setRangeZoomAxes(my_w.plot->xAxis,my_w.plot->yAxis);
my_w.plot->axisRect()->setRangeZoom(my_w.plot->yAxis->orientation());
}
else if (my_w.plot->xAxis2->selectedParts().testFlag(QCPAxis::spAxis)){
my_w.plot->axisRect()->setRangeZoomAxes(my_w.plot->xAxis2,my_w.plot->yAxis2);
my_w.plot->axisRect()->setRangeZoom(my_w.plot->xAxis2->orientation());
}
else if (my_w.plot->yAxis2->selectedParts().testFlag(QCPAxis::spAxis)){
my_w.plot->axisRect()->setRangeZoomAxes(my_w.plot->xAxis2,my_w.plot->yAxis2);
my_w.plot->axisRect()->setRangeZoom(my_w.plot->yAxis2->orientation());
}
else
my_w.plot->axisRect()->setRangeZoom(Qt::Horizontal|Qt::Vertical);
}
setRangeZoom(0)
如果您不想在未选择任何轴时进行任何缩放,则可以将最后一种情况更改为。
查看交互示例以获取更多选项。