PDA

View Full Version : Can QwtPlotPicker emit the selected signal for more than one mouse event?



cprokopiak
3rd February 2011, 16:25
Hi,

I am trying to create a QwtPlotPicker class that can select left and right boundary points on my QwtPlot. My original idea was to have the left mouse button select the left boundary and the right mouse button to select the right. However, when trying to implement this, I've noticed that I can only get the selected( QwtDoublePoint point ) SIGNAL function to work with only a left mouse button click. Even a CTRL+left mouse button does not emit the signal. Is it possible to have multiple button events emit the selected SIGNAL, or is it only active for QwtEventPatter::MouseSelect1? If it's the latter, I guess I would need to have independent pickers for both the left and the right boundaries?

I am running Qwt 5.2.0.

Here is my code:

signalPicker = new PlotPicker( canvas() );
signalPicker->setSelectionFlags( QwtPicker::PointSelection | QwtPicker::ClickSelection );
signalPicker->setRubberBandPen( QColor( Qt::gray ) );
signalPicker->setMousePattern( QwtEventPattern::MouseSelect1, Qt::LeftButton );
signalPicker->setMousePattern( QwtEventPattern::MouseSelect2, Qt::LeftButton, Qt::ControlModifier );
signalPicker->setMousePattern( QwtEventPattern::MouseSelect3, Qt::RightButton );
signalPicker->setMousePattern( QwtEventPattern::MouseSelect4, Qt::RightButton, Qt::ControlModifier );
signalPicker->setEnabled( false );
connect( signalPicker, SIGNAL( selected( QwtDoublePoint) ), this, SLOT( setSelectedPoint( QwtDoublePoint ) ) );
connect( signalPicker, SIGNAL( setLeft() ), this, SLOT( setSignalLeft() ) );
connect( signalPicker, SIGNAL( setRight() ), this, SLOT( setSignalRight() ) );
connect( signalPicker, SIGNAL( clearLeft() ), this, SLOT( resetSignalLeft() ) );
connect( signalPicker, SIGNAL( clearRight() ), this, SLOT( resetSignalRight() ) );

Thanks for your time.

d_stranz
4th February 2011, 18:44
Look at the source code for QwtPlotPicker and QwtPickerClickPointMachine. I think you'll see that the only time selected() is emitted is for a left click. It doesn't matter what you set the other event patterns to, only MouseSelect1 will result in a selected() signal.

So, since Qwt 5.2 doesn't let you change the picker machine (setStatemachine() is private in QwtPicker), you have to do some tricks: Look at the transition() methods in the QwtPicker and the QwtPickerClickPointMachine. Derive your own QwtPickerMachine class to do what you want (basically, use both left and right clicks to construct the same command list). Write your own QwtPlotPicker class and create an instance of your own picker machine as a member variable. Override the QwtPlotPicker::transition() method to call your machine instead of the default machine, but do everything else the same way.

I think that in 6.0, the setStateMachine() method is exposed, so you probably won't have to derive your own plot picker class but will only have to make the customized state machine.

It would probably help your app if you also changed the picker's transition() class to emit different signals on left and right click instead of just the single selected() event, because otherwise how will you tell which button was clicked?

Uwe
4th February 2011, 21:45
What about using using different pickers - one for each type of mouse click you want to have ?

Uwe

d_stranz
5th February 2011, 02:05
Good idea - I didn't realize that two pickers could be active at the same time. If they are both enabled, do they each get all of the mouse events?

Uwe
5th February 2011, 08:33
All of these helper classes for navigating/selecting on the plot canvas install an event filter ( QObject::installEventFilter), where they handle certain events posted to the canvas. As long as an event filter doesn't return true ( what the Qwt classes don't do ) the event is processed by all other installed event filters and in the end by the canvas itself.

Uwe