QCustomPlot 和 iRangeDrag 在第二个右边的 yAxis

QCustomPlot and iRangeDrag on second right yAxis

我正在尝试使右轴可拖动。

现在使用其中一个站点示例,我可以通过双击使第一个 yAxis 可拖动。

void MainWindow::mousePress()
{
// if an axis is selected, only allow the direction of that axis to be dragged
// if no axis is selected, both directions may be dragged

if (ui->customPlot->xAxis->selectedParts().testFlag(QCPAxis::spAxis))
    ui->customPlot->axisRect()->setRangeDrag(ui->customPlot->xAxis->orientation());
else if (ui->customPlot->yAxis->selectedParts().testFlag(QCPAxis::spAxis))
    ui->customPlot->axisRect()->setRangeDrag(ui->customPlot->yAxis->orientation());
else if (ui->customPlot->yAxis2->selectedParts().testFlag(QCPAxis::spAxis))
    ui->customPlot->axisRect()->setRangeDrag(ui->customPlot->yAxis2->orientation());
else
    ui->customPlot->axisRect()->setRangeDrag(Qt::Horizontal|Qt::Vertical);
}

我的图表有 2 条线,每条线都有不同的 yAxis。 我想要实现的是在第二个(右侧)yAxis 上实现相同的可拖动效果,称为 yAxis2。 使用下面的代码,即使我 select yAxis2,也是垂直拖动的 yAxis

我想问题出在 axisRect() 中,它只与左 yAxis 相关,而不是两者都相关。

我通过修改代码解决了问题,以便在右轴上也执行拖动调用。 如果看一下左轴上发生的情况,就会非常简单。