Originally Posted by
ruzik
i need to see coordinates not all the time, i need to see it if mouse moved near some point
I know, that i can redefine mouse move event in qwt symbolm but there no more easy way?
No you can't - QwtSymbol is no QWidget.
Instead you can follow the hint of pkj using a customized picker:
{
....
{
double dist = 10e10;
int index = -1;
const QwtPlotItemList& itmList = plot()->itemList();
for ( QwtPlotItemIterator it = itmList.begin();
it != itmList.end(); ++it )
{
{
double d;
int idx = c->closestPoint( pos, &d );
if ( d < dist )
{
curve = c;
index = idx;
dist = d;
}
}
}
const int maxPixels = 10;
if ( dist < maxPixels )
{
const QPointF pos
= curve
->sample
( index
);
text.sprintf( "%.4f, %.4f", pos.x(), pos.y() );
}
}
};
class YourPlotPicker:: public QwtPlotPicker
{
....
virtual QwtText trackerTextF( const QPointF &pos ) const
{
QwtPlotCurve *curve = NULL;
double dist = 10e10;
int index = -1;
const QwtPlotItemList& itmList = plot()->itemList();
for ( QwtPlotItemIterator it = itmList.begin();
it != itmList.end(); ++it )
{
if ( ( *it )->rtti() == QwtPlotItem::Rtti_PlotCurve )
{
QwtPlotCurve *c = static_cast<QwtPlotCurve *>( *it );
double d;
int idx = c->closestPoint( pos, &d );
if ( d < dist )
{
curve = c;
index = idx;
dist = d;
}
}
}
QString text;
const int maxPixels = 10;
if ( dist < maxPixels )
{
const QPointF pos = curve->sample( index );
text.sprintf( "%.4f, %.4f", pos.x(), pos.y() );
}
return QwtText( text );
}
};
To copy to clipboard, switch view to plain text mode
QwtPlotCurve::closestPoint() iterates over all points what might be too slow for many points. If can implement something faster using the characteristics of your samples ( f.e when they have increasing x values ) better implement it. In the worst case you need to introduce some spatial organized index like a quadtree.
Uwe
Bookmarks