PDA

View Full Version : making a RubberBand for selecting an area



Alex22
12th July 2016, 20:22
Hi,

I need to select an area with a RubberBand that returns QRectF::top, QRectF::bottom, QRectF::left, QRectF::right. For this I do this:



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


and by using zoomed (const QRectF &rect) signal, rect can be obtain.



connect(zoomer, zoomed (QRectF), this, slot_pos(QRectF));

void MyClass::slot_pos(QRectF pos)
{
qDebug() << pos.top << pos.bottom << pos.left << pos.right;
}


now I have this problem:
Mouse LeftButton causes zooming. I want to to select an area with a RubberBand without zooming by for example LeftButton +ctrl.

Uwe
13th July 2016, 06:37
QwtPlotZoomer - zooming = QwtPlotPicker;

The keys or mouse actions being used for starting,moving and terminating the selection is customizable.

Uwe

Alex22
13th July 2016, 16:01
Thanks Uwe, I used this and nothing happens and no RubberBand has been appeared:


QwtPlotPicker* picker= new QwtPlotPicker( canvas );

picker->setRubberBandPen( QColor( Qt::red ) );
picker->setTrackerPen( QColor( Qt::green ) );
picker->setMousePattern( QwtEventPattern::MouseSelect2,
Qt::RightButton, Qt::ControlModifier );

Uwe
13th July 2016, 19:43
This is your initial sequence to get something started:

QwtPlotPicker* picker= new QwtPlotPicker( plot->canvas() );
picker->setStateMachine( new QwtPickerDragRectMachine() );
picker->setRubberBand( QwtPlotPicker::RectRubberBand );
picker->setRubberBandPen( QColor( Qt::red ) );
picker->setTrackerPen( QColor( Qt::green ) );
picker->setTrackerMode( QwtPlotPicker::ActiveOnly );

connect( picker, SIGNAL( selected( const QRectF &rect ) ), ... );

Choose the type of state machine you like and check its docs, what type of event patterns are used by it. In case of the rectangle machines it is using QwtEventPattern::MouseSelect1 and QwtEventPattern::KeySelect1 - what means changing QwtEventPattern::MouseSelect2 ( like in your code snippet ) will have no effect.

Uwe