QCustomPlot Discussion and Comments

pixelsToCoordsReturn to overview


QVector<double> x;
for(int i = 0; i < 128; i++){
double scale = 2000;
for(int i = -64; i < 64; i++){
    x[i+64] = scale/128*i; 
ui->graph->xAxis->setRange(-0.5*scale, 0.5*scale);

I use mouse click event.

double px, py;
ui->graph->graph(0)->pixelsToCoords(event->pos(), px, py);

But I recieved 'px' in scaled values.
How to convert it to QVector data index? In my case value should be between 0 and 128.

You use findBegin():

idx = ui->graph->graph(0)->findBegin(px);

Note that this will return exact or nearest index since the translated mouse pos px might not be on an exact graph key.

Thank you!