QCustomPlot Discussion and Comments

Using Arrow Keys to scroll through plotReturn to overview

Hey,
I have been using QCustomPlot for a few weeks now and it is great. Recently i have been plotting fairly long data sets and have been scrolling through just using the drag function. This gets annoying after a while and I'm thinking it would be great to just hit the left or right arrow key to move along a time axis.

I don't have any code developed for this but would like to start a conversation for anyone interested/ anyone who has implemented something like this.

If i get something going i will post it.

Turned out to be relatively simple... Didn't know about the moveRange(double) function. right now I just added two hidden push buttons with shortcuts to the right and left arrow keys to trigger these slots. I'm sure there is a way to hook up a signal directly to a keyboard key.

void MainWindow::on_pushRight_pressed()
{

double low = ui->customPlot->xAxis->range().lower;
double high = ui->customPlot->xAxis->range().upper;
int stepsPerPress = 8;

ui->customPlot->xAxis->moveRange((high - low) / 8);
ui->customPlot->replot();
}

void MainWindow::on_pushLeft_pressed()
{
double low = ui->customPlot->xAxis->range().lower;
double high = ui->customPlot->xAxis->range().upper;
int stepsPerPress = 8;

ui->customPlot->xAxis->moveRange(-((high - low) / stepsPerPress));
ui->customPlot->replot();
}

QShortcut is the class you were looking for:

http://qt-project.org/doc/qt-5.1/qtwidgets/qshortcut.html#details

Just create two instances, one for the left arrow and one for the right arrow button and connect the activate() signal to your push slots.