I have trouble with mouseEvents as well.
I want to send the values the Tracker displays as an Signal when the plot is clicked at that point.
I tried the following
void QSpectrogramPlot::initWidget()
{
delete m_picker;
connect(m_picker, SIGNAL(selected(const QwtPolygon &)), this, SLOT(OnPickerPointSelected(const QwtPolygon &)));
// emit the position of clicks on widget
}
void QSpectrogramPlot::OnPickerPointSelected(const QwtPolygon & poly)
{
emit selectedPoint(poly[0]);
m_picker->reset();
}
void QSpectrogramPlot::initWidget()
{
delete m_picker;
m_picker = new QwtPicker(this);
connect(m_picker, SIGNAL(selected(const QwtPolygon &)), this, SLOT(OnPickerPointSelected(const QwtPolygon &)));
// emit the position of clicks on widget
m_picker->setSelectionFlags(QwtPicker::PointSelection | QwtPicker::ClickSelection);
}
void QSpectrogramPlot::OnPickerPointSelected(const QwtPolygon & poly)
{
emit selectedPoint(poly[0]);
m_picker->reset();
}
To copy to clipboard, switch view to plain text mode
The rest to make sure that the Polygon is empty at the next click. I do not want it to be filled with points.
However the reset is not possible to be used - does not compile.
How would I do it then?
Also QwtPolygon would be the wrong argument if I want the points of the tracker, which must be QwtPolygonF. So how do I get the points of the tracker instead ?
EDIT:
Found a solution
connect(m_picker, SIGNAL(selected(const QwtDoublePoint &)), this, SLOT(OnPickerPointSelected(const QwtDoublePoint &)));
// emit the position of clicks on widget
}
void QSpectrogramPlot::OnPickerPointSelected(const QwtDoublePoint & p)
{
emit selectedPoint(point);
qDebug
() <<
QString("x: %1, y: %2").
arg(point.
x()).
arg(point.
y());
}
m_picker = new QwtPlotPicker(this->canvas());
connect(m_picker, SIGNAL(selected(const QwtDoublePoint &)), this, SLOT(OnPickerPointSelected(const QwtDoublePoint &)));
// emit the position of clicks on widget
m_picker->setSelectionFlags(QwtPicker::PointSelection | QwtPicker::ClickSelection);
}
void QSpectrogramPlot::OnPickerPointSelected(const QwtDoublePoint & p)
{
QPointF point = p;
emit selectedPoint(point);
qDebug() << QString("x: %1, y: %2").arg(point.x()).arg(point.y());
}
To copy to clipboard, switch view to plain text mode
Bookmarks