PDA

View Full Version : qwtPlotPicker: simple problem to start understanding how it works



fatecasino
4th January 2011, 02:58
I have been reading several examples and threads about qwtPlotPicker, but most people have extreme problems for the standards of my understanding, so the solutions are more confusing than answering to my questions.

Problem

create a picker
when you click
you leave mark on the plot/canvas, a cross "+", an "x", whatever
get the clicked coordinates in a variable


So far, I have reached this point:


mypicker = new QwtPlotPicker(m_amp->canvas());
mypicker->setTrackerMode(QwtPicker::AlwaysOn);
mypicker->setRubberBand(QwtPicker::VLineRubberBand);//not sure for this!
mypicker->setSelectionFlags(QwtPicker::PointSelection | QwtPicker::ClickSelection);

any suggestions to move on?!

fatecasino
4th January 2011, 21:51
well, I managed some steps.
I have created a picker:


d_picker = new QwtPlotPicker(QwtPlot::xBottom, QwtPlot::yLeft,
QwtPlotPicker::CrossRubberBand, QwtPicker::AlwaysOn,
myPlot->canvas());
d_picker->setStateMachine(new QwtPickerDragRectMachine());
d_picker->setRubberBandPen(QColor(Qt::green));
d_picker->setRubberBand(QwtPicker::CrossRubberBand);
d_picker->setTrackerPen(QColor(Qt::blue));

but I am still missing the rest:



when you click you leave mark on the plot/canvas, a cross "+", an "x", whatever
get the clicked coordinates in a variable

the methods


void selected (const QwtDoublePoint &pos)
void selected (const QwtDoubleRect &rect)
void selected (const QwtArray< QwtDoublePoint > &pa)

are signals. Should i try to make a connection between these signals and a custom slot where I will store the clicked values? Which setStateMachine is the proper one in order to get 4 separate points of the plot?

Added after 22 minutes:

Is the following combination possible to work?


d_picker = new QwtPlotPicker(QwtPlot::xBottom, QwtPlot::yLeft,
QwtPlotPicker::CrossRubberBand, QwtPicker::AlwaysOn,
myPlot->canvas());
d_picker->setStateMachine(new QwtPickerClickPointMachine());
d_picker->setRubberBandPen(QColor(Qt::green));
d_picker->setRubberBand(QwtPicker::CrossRubberBand);
d_picker->setTrackerPen(QColor(Qt::blue));


connect(d_picker, SIGNAL (selected(const QwtDoublePoint &)), myPlot, SLOT (setPoint1(const QwtDoublePoint &)) );



void my2dPlot::setPoint1(const QwtDoublePoint & po1)
{
point1 = po1;

QString x1,y1;
x1.setNum(point1.x());
y1.setNum(point1.y());
QString info("x >>> " + x1 + " y >>> " +y1);

showInfo(info);

}

d_stranz
5th January 2011, 04:43
If you set the picker machine to QwtPickerClickPointMachine (ClickSelection | PointSelection) you will get only a single point. That is, the selected( const QwtDoublePoint & ) signal will be emitted. If you want more than one point, then you need to use PolygonSelection instead of PointSelection. In that case, the selected( const QwtArray< QwtDoublePoint > & ) signal will be emitted. RectSelection results in a QwtDoubleRect signal.

The picker does not put "x" or other marks on the plot, as far as I know. So your #3 idea is not correct.

The picker does not store the selected points. That's what the signals are there for. You connect a slot to the signal, and the save the points yourself if you need them.

FelixB
5th January 2011, 07:54
use this signal and connect it to a custom slot. This signal is emitted when the user clicks if you have set your picker to "PointSelection". For setting a mark, you have to use a QwtPlotMarker.

example:


myMarker = new QwtPlotMarker();
myMarker ->setSymbol(QwtSymbol(QwtSymbol::Cross, QBrush(Qt::darkRed), QPen(Qt::red, 2, Qt::DashLine), QSize(100,100)));
myMarker->attach(myPlot);
myMarker->setVisible(false);

void clicked(const QwtDoublePoint &pos)
{
myMarker->setVisible(true);
myMarker->setValues(pos);
myPlot->replot(); // replot to show/refresh marker
}

hope this helps!
Felix