QCustomPlot Discussion and Comments

Synchronize several QCustomPlot on xAxisReturn to overview

Hello, on my QMainWindow I have several QCustomPlot that show different real-time data. They virtually "share" the xAxis (time).
I would like to keep them in sync when the user move one of them.

I've tried:

connect(ui->plotPosition->xAxis, SIGNAL(rangeChanged(QCPRange)), ui->plotSpeed->xAxis, SLOT(setRange(QCPRange)));

but this signal is not emitted when is the user that move the graph.
Which one I have to catch?

Second question is possible to link all togheter without create a loop? I.e.:

connect(ui->plot1->xAxis, SIGNAL('''userPan'''), ui->plot2->xAxis, SLOT('''userPan'''));
connect(ui->plot1->xAxis, SIGNAL('''userPan'''), ui->plot3->xAxis, SLOT('''userPan'''));
connect(ui->plot2->xAxis, SIGNAL('''userPan'''), ui->plot1->xAxis, SLOT('''userPan'''));
connect(ui->plot2->xAxis, SIGNAL('''userPan'''), ui->plot3->xAxis, SLOT('''userPan'''));
connect(ui->plot3->xAxis, SIGNAL('''userPan'''), ui->plot1->xAxis, SLOT('''userPan'''));
connect(ui->plot3->xAxis, SIGNAL('''userPan'''), ui->plot2->xAxis, SLOT('''userPan'''));

Any graph the user interacts with should update the others.
Thanks in advance!

> but this signal is not emitted when is the user that move the graph.
The signal is emitted.

You should also make sure that the plotSpeed is replotted in sync with the others. (e.g. connect signal afterReplot with replot of the others.)
Note that QCP supports multiple axis rects in one widget, which might be more convenient in your case, compared with multiple widgets.

It is possible to connect rangeChanged/setRange in a loop – QCP will stop emitting rangeChanged, if setRange is called with a range that is already the current axis range.

mmm... there should be something wrong in my code:

QSharedPointer<QCPAxisTickerDateTime> timeTicker(new QCPAxisTickerDateTime);

ui->plotPosition->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom | QCP::iSelectPlottables);

ui->plotSpeed->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom | QCP::iSelectPlottables);

connect(ui->plotPosition->xAxis, SIGNAL(rangeChanged(QCPRange)), ui->plotSpeed->xAxis, SLOT(setRange(QCPRange)));

connect(ui->plotPosition, SIGNAL(afterReplot()), ui->plotSpeed, SLOT(replot(QCustomPlot::RefreshPriority)));

Now, if I explicitly set the range of plotPlosition:

ui->plotPosition->xAxis->setRange(qMax(0.0, m_keyTime - 30.0), qMax(30.0, m_keyTime), Qt::AlignLeft);

both plots are updated hence I assume the signal is emitted.
But if I move the graph of plotPosition with the mouse, plotSpeed isn't affected.

I will try the multiple axis rects in one widget, but I would like to understand where is my mistake here.