QCustomPlot Discussion and Comments

Updating Axis Range in BackgroundReturn to overview

Hello to All of you,

first of all i wanna thank the creator of the libary for his insane work!

My Code: I have written a programm which is displaying live data via a timer. So for every (100ms) data from my device is going through my programm as input.
The problem: In my Timer function there is also the function setRange() so the x-axis is manipulated. When i try now to drag or to zoom my graph the axis will instantly be set again to the given paramaters in setRange(in my timer function).
My Question: Is there a way to update the axis without setting the range ?
My Tries: I tried to implement rescaleAxis and so on outside my timer function. The problem by this is that i didnt represent the graphs the way i wanted to : show updated data plus not the data from beginning. (like its moving forward)

Sorry for my bad english.
Hope you can help me out!

the way i do this is i set the bounding range when i adjust the data and then set the actual range on zoom. if they attempt to zoom out more than the bounding range, it will just set the zoom to the bounding range.

I'm using 1.3 and had to implement all this myself, but i think they implemented some of that in the 2.0 code already.

You may try this for drag plot in real time mode (not tested):
(About key, timeBetweenDotsSec and Qt::AlignRight you can see at the bottom)

{
    ...
    bool mousePress = false;
}

void replotGraph(){
    if ( ! mousePress )
        ui->customPlot->xAxis->setRange(key - timeBetweenDotsSec, ui->customPlot->xAxis->range().size(), Qt::AlignRight);
}

void keyPressEvent(QKeyEvent   *event){
    mousePress = true;
}

void mouseRelease (QMouseEvent *event){
    mousePress = false;
}

I use two mode of zooming:
1) in real time data
2) in static (paused data)

This function switch between two modes:
(StreamState::Open is real time mode)

void setStreamState(const StreamState &state)
{
    if (state == Open){
        ui->customPlot->setInteraction(QCP::iRangeZoom, false);
        connect    (ui->customPlot, SIGNAL(mouseWheel(QWheelEvent *)), this, SLOT(wheelZoom(QWheelEvent *)));
    }else{
        ui->customPlot->setInteraction(QCP::iRangeZoom, true);
        disconnect (ui->customPlot, SIGNAL(mouseWheel(QWheelEvent *)), this, SLOT(wheelZoom(QWheelEvent *)));
    }
    streamState = state;
}

Function wheelZoom(QWheelEvent *event) call only in real time mode. In this function change only left border, right border is remain in place:
(key - x coord of last point, timeBetweenDotsSec - space in x axis between two dots. Qt::AlignRight) - for view last points of data on the right.)

void wheelZoom(QWheelEvent *event){
    double delta = event->delta()/1200.0;
    double rangexAxis = ui->customPlot->xAxis->range().size();
    delta = delta * rangexAxis;
    ui->customPlot->xAxis->setRange(key - timeBetweenDotsSec, rangexAxis + delta, Qt::AlignRight);
    ui->customPlot->replot();
}

In static mode I use only ui->customPlot->setInteraction(QCP::iRangeZoom).

I hope it can help you

Thank you both for your answers.

Igor answer solved the problem :)

Have a nice day !