Search code examples
c++qwt

Qwt - how to get the select point index with QwtPlotPicker


I plot complex data using QwtPlot, so, I reimplement QwtSeriesData for converting my data into QPointF. The "sample(int)" converts MyObject to QPointf. My QwtSeriesData data manages a

myVector=vector<MyObject>;

Now, I need to select point drawn into my plot. I try to use QwtPlotPicker but it only returns a QPointF.

How to get the index "idx" of the selected point in order to get myObject=myVector[idx]?


Solution

  • Use the closestPoint() method in the curve.

    int QwtPlotCurve::closestPoint  (   const QPoint &      pos,
        double *    dist = NULL 
    ) 
    

    It will return the id of the closest point in the curve!

    Hope this helps you.