QCustomPlot Discussion and Comments

How to only zoom the xAxis without zooming the yAxis?Return to overview

Now I'm doing some realtime-plot.

setInteractions(QCP::iRangeDrag | QCP::iRangeZoom);

this code can zoom in/out all the xAxis and yAxis.But i only want to zoom the xAxis,to display more data.How to do?Thanks for your answer!!

see user interactions tutorial on the left

You have 2 choices:

1. If you have Axis (X and Y) you can make selectable axis and when you click on it (exemple on Y axis) when you scrool up/down only X axis are zooming.

2. if you whan fix the Y axis. You can redefined mouseEvent to set scale of X axis and Y axis as previous for Y.

Tell me what you want ?

@Franck I think you don't need to redefine mouseEvent. Why not just call setRangeDragAxes with no axis as vertical, or setRangeDrag(Qt::Horizontal). That works without redefining mouseEvent. (Or setRangeZoom for zoom)

connect(ui->customPlot, SIGNAL(mouseWheel(QWheelEvent*)), this, SLOT(mouseWheel())); 

///....

void MainWindow::mouseWheel() 
{
    if( QApplication::keyboardModifiers() == Qt::ControlModifier ) {
            ui->customPlot->axisRect()->setRangeZoom(Qt::Horizontal);
            qDebug() << "----------x Axis changed by wheel-----------";
        } else {
            ui->customPlot->axisRect()->setRangeZoom(Qt::Horizontal | Qt::Vertical);
            qDebug() << "----------xy Axis changed by wheel-----------";
    }

    qDebug() << "----------zoomed by wheel-----------";
}

it's worked for me