user217354
user217354

Reputation: 304

QCustomPlot and iRangeDrag on second right yAxis

I'm trying to make the right axis draggable.

Right now using one of the site examples im able to make the first yAxis draggable by double clicking on it.

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);
}

My graphs has 2 lines, each with a different yAxis. What I would like to achieve is the same draggable effect on the second (on the right) yAxis which is called yAxis2. With the code below even if I select the yAxis2, it is the yAxis which is dragged vertically.

I guess the problem is in axisRect() which is related only to the left yAxis rather than both of them.

Upvotes: 1

Views: 504

Answers (2)

Dan Hankewycz
Dan Hankewycz

Reputation: 11

I was able to get both yAxis and yAxis2 to drag together by calling QCPAxisRect::setRangeDragAxes().

Note: If you still want the xAxis to drag with the mouse, then you need to have it in the list too because the defaults will get overwritten.

QList<QCPAxis *> draggableAxes = {xAxis,yAxis,yAxis2};
myPlot->axisRect()->setRangeDragAxes(draggableAxes);

If you want similar behavior for zoom interactions as well, there's a setter for that too! QCPAxisRect::setRangeZoomAxes()

Upvotes: 1

user217354
user217354

Reputation: 304

I solved by modifiying the code in order to perform the drag calls on the right axis as well. It is pretty straightforward if one takes a look on what happens on the left axis.

Upvotes: 0

Related Questions