PDA

View Full Version : Clicking on a plot



Ronayn
29th April 2011, 13:09
I am using the spectrogram example code and I am a bit confused on how to detect a and respond to a mouse click (or mouse button press) on the spectrogram.

Which object receives the mouse click? The spectrogram plot item? The plot's canvas, or the plot itself?

Do I have to reimplement the mouse event function? Or are there signals from any of the above objects that I should be connecting to?

On a related note, I need to modify the way the Zoomer class responds to mouse presses and I dont know how to do that. I'd like a left mouse click to just report the X,Y location on the plot, a right mouse press to start the zooming selection and a right mouse release to stop the selection and zoom, and finally a shift-right click to reset the zoom state back to the original.

Uwe
29th April 2011, 13:59
Which object receives the mouse click? The spectrogram plot item? The plot's canvas, or the plot itself?
The canvas.

Note, that QwtPlotPicker offers an easy to use API to handle clicks on the canvas. F.e you have signals with the clicked position already translated into plot coordinates.


I'd like a left mouse click to just report the X,Y location on the plot, ...

Introduce an additional QwtPlotPicker and don't do this with your zoomer.


.. a right mouse press to start the zooming selection and a right mouse release to stop the selection and zoom, and finally a shift-right click to reset the zoom state back to the original.


zoomer->setMousePattern(
QwtEventPattern::MouseSelect1, Qt::RightButton );
zoomer->setMousePattern(
QwtEventPattern::MouseSelect2, Qt::RightButton, Qt::ShiftModifier );

Don't forget to define the mouse bindings for stepping forward and backward in th zoom stack.

Uwe