Restricting cursor movement (or appearance) to follow only the curve
Hi everyone,
It's my first week learning to use Qt and Qwt, so please bear with me. I'd like to make a plotting function with cursor similar to that of the BodePlot with:
(1) a curve,
(2) cursor display with the values being shown,
(3) restrict the cursor's movements to slide along the values of the curve only when within the plot, i.e. given mouse position x, fixing mouse position y.
I've taken apart the code in the Bode example and kept only a few elements which satisfy points (1) and (2) but would appreciate some suggestions, hints or pseudocode for doing (3)!
Thanks very much!
Re: Restricting cursor movement (or appearance) to follow only the curve
I'm not sure what you mean in 3).
Are you talking about mouse cursor and restricting it's movement?
I'm not sure if that's a good idea.
In my opinion you should not play with the mouse cursor, instead you can add a marker which could follow the curve.
As to 'how to'.
You can install event filter on the canvas to get mouse move events only when mouse cursor is over the canvas.
Having X screen coordinate you can translate it to X world coordinate using QwtPlot::transform().
Now the difficult part: you can't use QwtPlot facilities to get curve Y value at cetain X (at least I don't know how).
You have to do it yourself and it will depend on data model you have.
In worst case, where your data takes forever to find Y for X you could use canvas cache to find the Y.
Just interogate all pixels in X column (where X comes from mouse move event over the canvas) in the cache and look for first black pixel you find.
This way you get Y position in the canvas which you can map to screen using QwtPlotCanvas::mapToGlobal().
I haven't tested it but I think it should work :)
Re: Restricting cursor movement (or appearance) to follow only the curve
Quote:
Originally Posted by
Spitfire
I'm not sure what you mean in 3).
Are you talking about mouse cursor and restricting it's movement?
It should be about the rubber band of the picker.
Quote:
Originally Posted by
Spitfire
Now the difficult part: you can't use QwtPlot facilities to get curve Y value at cetain X (at least I don't know how).
Read also: http://www.qtcentre.org/threads/4505...point-of-curve
Uwe
Re: Restricting cursor movement (or appearance) to follow only the curve
I guess it's not really about restricting the mouse movement, but that when I'm inside of the graph, I have a single point tracing over the curve. I settled with a QwtPickerTrackerMachine which tracks the movements of the cursor and then plots an extra point on my curve following the location of the cursor. If I can now only get rid of the "+" cursor from appearing... (related to my other post).