I'm having headaches with the fact that converting QCPDataSelection indexes to keys and then the resulting keys to indexes does not lead to equal results:

// This slot is called when the user changed the selection on the plot
void myUI::slot_graphSelectionChanged(const QCPDataSelection &s)
      // keys are exclusively integers in my graph
      quint32 start = g->data()->at(s.dataRange().begin())->key;
      quint32 end = g->data()->at(s.dataRange().end()-1)->key;


// this is used to change the selection, it is either called by the slot or from the outside to change it programmatically
void myUI::setInterval(quint32 start, quint32 end)
  // avoid re-emitting signal

  int start_idx = g->findBegin(start);
  int end_idx = g->findBegin(start);



I notice that whatever method I use (findBegin() / findEnd()) with or without extendedRange, I cannot get back to the original selection indexes got from the slot.

The slot method is doing the job well: the indexes and keys are correct and do match the selection rect of the user.
The setInterval() is causing problems because I can't manage the find() methods to return the same indexes.

Please advise on the correct way to go back and forth from index to key.