qwtPlotPicker: simple problem to start understanding how it works
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:
Code:
mypicker
->setTrackerMode
(QwtPicker::AlwaysOn);
mypicker
->setRubberBand
(QwtPicker::VLineRubberBand);
//not sure for this!
any suggestions to move on?!
Re: qwtPlotPicker: simple problem to start understanding how it works
well, I managed some steps.
I have created a picker:
Code:
myPlot->canvas());
d_picker
->setRubberBandPen
(QColor(Qt
::green));
d_picker
->setRubberBand
(QwtPicker::CrossRubberBand);
d_picker
->setTrackerPen
(QColor(Qt
::blue));
but I am still missing the rest:
Code:
when you click you leave mark on the plot/canvas, a cross "+", an "x", whatever
get the clicked coordinates in a variable
the methods
Code:
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?
Code:
myPlot->canvas());
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 &)) );
Code:
void my2dPlot::setPoint1(const QwtDoublePoint & po1)
{
point1 = po1;
x1.setNum(point1.x());
y1.setNum(point1.y());
QString info
("x >>> " + x1
+ " y >>> " +y1
);
showInfo(info);
}
Re: qwtPlotPicker: simple problem to start understanding how it works
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.
Re: qwtPlotPicker: simple problem to start understanding how it works
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:
Code:
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