Hello,
I have got the same problem, because of size 0 of the boundingRect() the item cannot be found:
void Plot::cursorSelected(const QwtDoublePoint &Point)
{
//selectedPoint = NULL;
std::cout << "in Plot::cursorSelected, selectedPoint = " << selectedPoint << std::endl;
const QwtPlotItemList& List = itemList();
QwtPlotItemIterator Iter = List.begin();
for ( QwtPlotItemIterator it = List.begin();it != List.end(); ++it )
{
std::cout << "(*it) "<< (*it) << std::endl;
{
QwtDoubleRect rec = mark->boundingRect();
std::cout << "mark->boundingRect()" <<rec.width()<<rec.height()<< std::endl;
if(mark->boundingRect().contains(Point)){
std::cout << "MATCH" << std::endl;
selectedPoint = dynamic_cast<QwtPlotMarker*>(mark);
std::cout << "selectedPoint = " << selectedPoint << std::endl;
}
else selectedPoint = NULL;
}
}
void Plot::cursorSelected(const QwtDoublePoint &Point)
{
//selectedPoint = NULL;
std::cout << "in Plot::cursorSelected, selectedPoint = " << selectedPoint << std::endl;
const QwtPlotItemList& List = itemList();
QwtPlotItemIterator Iter = List.begin();
for ( QwtPlotItemIterator it = List.begin();it != List.end(); ++it )
{
std::cout << "(*it) "<< (*it) << std::endl;
if ( (*it)->rtti() == QwtPlotItem::Rtti_PlotMarker )
{
QwtPlotMarker *mark = ((QwtPlotMarker*)(*it));
QwtDoubleRect rec = mark->boundingRect();
std::cout << "mark->boundingRect()" <<rec.width()<<rec.height()<< std::endl;
if(mark->boundingRect().contains(Point)){
std::cout << "MATCH" << std::endl;
selectedPoint = dynamic_cast<QwtPlotMarker*>(mark);
std::cout << "selectedPoint = " << selectedPoint << std::endl;
}
else selectedPoint = NULL;
}
}
To copy to clipboard, switch view to plain text mode
What do you mean by using Pixel coordinates? Di you mean I have to transform them like that? :
double x = this->transform(mark->xAxis(),Point.x());
double y = this->transform(mark->yAxis(),Point.y());
QwtDoublePoint trPoint = QwtDoublePoint(x,y);
double x = this->transform(mark->xAxis(),Point.x());
double y = this->transform(mark->yAxis(),Point.y());
QwtDoublePoint trPoint = QwtDoublePoint(x,y);
To copy to clipboard, switch view to plain text mode
I also uses this, but it does not work too. Perhaps because I did not expansed the size of boundingRect. How can I do it?
Bookmarks