PDA

View Full Version : how to get the (x, f(x)) values under the cursor?



Vincenzo
14th March 2009, 13:07
Hi,

I have a QwtPlot. I'd like to get the value of point under the mouse cursor. Yet I can recieve the coordinates:


QwtPicker *picker = new QwtPicker(this);
picker->setTrackerMode(QwtPicker::AlwaysOn);


,but how can I get the value of x and f(x), also how should I convert coordinates to values, and vice versa?

Furthermore, how could I insert text to the QwtPlot, because I want put the values next to the points.

Please, insert short example code, since I'm absolute beginner... :(
Thank's in advance.

GNU/Varan
14th April 2009, 10:49
There's the method <int QwtPlotCurve::closestPoint(const QPoint &pos, double *dist)>.
It returns index of the point, and you can call curve.x(index) and curve.y(index) to find x and y.
You can see the qwt example <event_filter>, file <canvaspicker.cpp>, method <void CanvasPicker::select(const QPoint &pos)> for one of the possible implementations.