PDA

View Full Version : How to get vertical/horizontal zoom box?



knicewar
18th March 2010, 16:52
I'm using QwtPlot with a zoomer and panner and everything is fine. But the users would like to be able to optionally constrain the box zoom to be horizontal or vertical. In other words, they would like to hold down shift while dragging the mouse and have the top y position of the zoom box be fixed at 0 and the bottom y position fixed at the bottom of the canvas. The x range of the box would be as normal. The drawn rubber band rectangle should also reflect this. Similarly, when Ctrl is held down while dragging the mouse, the box would stretch in x from 0 to the canvas width. I see in QwtPicker that there is a HLineRubberBand and VLineRubberBand which sound like what I want but I can't seem to get them to work like I expect. I also have no idea how to hook them up to the shift/ctrl key modifiers for the mouse drag events.

Has anyone done something like this? Is there an easy way to do it other than hacking drawRubberBand()?
Thanks.

Uwe
19th March 2010, 01:03
Obviously you are looking for a picker selecting a point ( not a zoomer selecting a rectangle ) Look at the bode example: if you don't enable the Zoom Button an picker is active showing a crosshair ( QwtPicker::CrossRubberBand ). Instead you can also have a QwtPicker::HLineRubberBand or QwtPicker::VLineRubberBand.

QwtPicker is derived from QwtEventPattern. Read the docs how to change the mouse/key events, that trigger the selection of your picker.

Uwe

knicewar
19th March 2010, 18:00
I'm sorry if that's not so obvious to me. The user wants to click and drag a zoom region (that might have a max vertical or horizontal extent depending on the modifier). That sure sounds like a rectangle selection to me and not a point selection, but maybe I'm not understanding what a point selection means. The picker in the bode example doesn't look like what I'm after because it isn't zooming on a region selected by the user.

I have read the docs on mouse/key events but I have found nothing that describes how to add a shift modifier to the mouse drag event and how to hook in code that will make the rectangle maximize in vertical or horizontal directions. I tried implementing widgetMouseMoveEvent in my zoomer (which derives from QwtPlotZoomer). I can get the modifier and have tried creating a new event based on the original one but with changed position and no modifier and then I call QwtPlotZoomer::widgetMouseMoveEvent(event). But this doesn't work. Even if all I do is create a copy of the event (using the copy constructor), it still doesn't work, so obviously there is something in the event that isn't getting copied.

Thanks.

grissiom
23rd March 2010, 04:09
Have a look at this: http://qwt.sourceforge.net/class_qwt_event_pattern.html#f48dc808ac5e125eeed41 a4c0285d1ea the MouseSelect4 is Qt::LeftButton + Qt::ShiftButton. It's maybe what you want.