我正在尝试使右轴可拖动。
现在使用其中一个站点示例,我可以通过双击使第一个 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
。
使用下面的代码,即使我选择了 yAxis2
,也是垂直拖动的 yAxis
。
我猜问题出在 axisRect() 中,它只与左侧 yAxis 相关,而不是两者都相关。
最佳答案
我通过修改代码来解决问题,以便在右轴上也执行拖动调用。 如果看一下左轴上发生的情况,就会非常简单。
关于c++ - QCustomPlot 和 iRangeDrag 在第二个右边的 yAxis,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39530718/