View Full Version : howto get value at Tracker Point
pospiech
9th February 2009, 09:50
In my zoomer class I also set the tracker:
virtual QwtText trackerText( const QwtDoublePoint& p ) const
{
QwtText t( QwtPlotPicker::trackerText( p ));
QColor c(Qt::white);
c.setAlpha(180);
t.setBackgroundBrush( QBrush(c) );
return t;
}
This returns the axis coordinates.
I would also like to display the vlaue at the current point. However I do not know how to access this value at this point. The qwtPlot istself is known as the pointer 'plot' within the Zoomer class.
StefanK
9th February 2009, 10:53
Hello
I once implemented following method called by the trackerText() method. May be that helps?
bool PlotPicker::curveSelected(const QPoint pMousePos, PlotCurve* &pPlotCurve, double &pYValue) const
{
double lDist = 10e10;
int lIndex = -1;
// get nearest curve point by iterating over plot items, filtering for curves and calculating minimum distance
const QwtPlotItemList& lPlotItemList = plot()->itemList();
for (QwtPlotItemIterator lPlotItemIterator = lPlotItemList.begin(); lPlotItemIterator != lPlotItemList.end(); ++lPlotItemIterator)
{
if ((*lPlotItemIterator)->rtti() == QwtPlotItem::Rtti_PlotCurve)
{
PlotCurve *lTmpCurve = (PlotCurve*)(*lPlotItemIterator);
double lTmpDist;
int lTmpIndex = lTmpCurve->closestPoint(pMousePos, &lTmpDist);
if (lTmpDist < lDist && lTmpIndex > -1)
{
pPlotCurve = lTmpCurve;
lDist = lTmpDist;
lIndex = lTmpIndex;
}
}
}
// check if mouse position is in tolerance
if (pPlotCurve && lDist < _pix_tolerance_)
{
pYValue = pPlotCurve->y(lIndex);
return true;
}
pPlotCurve = 0;
return false;
}
Within the trackerText() the call is..
//..... some preparations
// check if tracker text shall be displayed
if(mTrackerValueEnable)
{
double lSelectedYValue = 0.0;
PlotCurve* lSelectedCurve = 0;
if (curveSelected(pMousePos, lSelectedCurve, lSelectedYValue))
{
lLabel.append(QString("\n%1").arg(QString::number(lSelectedYValue)));
//..... whatever needed
}
}
QwtText lText(lLabel);
QColor lBackground(Qt::lightGray);
lBackground.setAlpha(_text_background_alpha_);
lText.setBackgroundBrush(QBrush(lBackground));
return lText;
Regards
Stefan
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.