PDA

View Full Version : Double-Click Zoom out feature



novackb
31st January 2011, 15:13
I'm attempting to implement a double-click zoom out feature to mimic Matlab behavior. I've successfully implemented a custom QwtPickerClickPointMachine which catches the double-click of mouse button 1 and I can perform the necessary actions.

My problem is I still need the zoom capability provided in the QwtPlotZoomer class which I think uses the QwtPickerDragRectMachine as the QwtPickerMachine. When I use the setStateMachine() method on the zoomer instance it replaces the current QwtPickerMachine with my custom PickerMachine, which is exactly as I would expect based on documentation. So I gain my double-click functionality but lose the zoom functionality.

So my question is how do I use the functionality provided in my custom Picker Machine and the QwtPickerDragRectMachine at the same time within my QwtPlotZoomer? Or is there a much easier approach that I'm just overlooking.

Any advice is appreciated.
Thanks!

FYI: working with qwt6.0.0_rc5

FelixB
31st January 2011, 16:01
why don't you use a QwtPlotZoomer and call "zoom(0)" when you want to zoom out? your approach sounds a bit complicated to me...

novackb
31st January 2011, 16:09
I agree it seems complicated, but customer has requested the double-click zoom out capability because their users are so familiar with current Matlab plot functionality.

I am already using a zoomer that I pulled and modified slightly from one of the examples:

// LeftButton for the zooming
// MidButton for the panning
// RightButton: zoom out by 1
// Ctrl+RightButton: zoom out to full size

QwtPlotZoomer* zoomer = new QwtPlotZoomer(canvas());
zoomer->setRubberBandPen(QColor(Qt::red));
zoomer->setTrackerPen(QColor(Qt::red));
zoomer->setMousePattern(QwtEventPattern::MouseSelect2,
Qt::RightButton, Qt::ControlModifier);
zoomer->setMousePattern(QwtEventPattern::MouseSelect3,
Qt::RightButton);

Now I'm trying to somehow 'capture' a Qt::LeftButton double-click which will then use zoom(0) as you mention.

FelixB
31st January 2011, 16:25
zooming out via double click is nothing complicated ;) just your ideas with statemachines etc... ;)

install an event filter on your canvas and react on the doubleclick event. that's the way I do it...

Uwe
31st January 2011, 19:53
Now I'm trying to somehow 'capture' a Qt::LeftButton double-click which will then use zoom(0) as you mention.


class YourZoomer: public QwtPlotZoomer
{
YourZoomer( ... )
{
// disable MouseSelect2 ( default for zooming out )
setMousePattern(QwtEventPattern::MouseSelect2, Qt::NoButton );
}
...
virtual void widgetMouseDoubleClickEvent( QMouseEvent *me )
{
if ( me->button() == ... )
zoom( 0 );
}
};

Untested,
Uwe