Results 1 to 2 of 2

Thread: howto get value at Tracker Point

  1. #1
    Join Date
    Feb 2008
    Posts
    157
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default howto get value at Tracker Point

    In my zoomer class I also set the tracker:
    Qt Code:
    1. virtual QwtText trackerText( const QwtDoublePoint& p ) const
    2. {
    3. QwtText t( QwtPlotPicker::trackerText( p ));
    4.  
    5. QColor c(Qt::white);
    6. c.setAlpha(180);
    7. t.setBackgroundBrush( QBrush(c) );
    8.  
    9. return t;
    10. }
    To copy to clipboard, switch view to plain text mode 
    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.

  2. #2
    Join Date
    Jan 2009
    Posts
    17
    Thanks
    6
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: howto get value at Tracker Point

    Hello

    I once implemented following method called by the trackerText() method. May be that helps?

    Qt Code:
    1. bool PlotPicker::curveSelected(const QPoint pMousePos, PlotCurve* &pPlotCurve, double &pYValue) const
    2. {
    3. double lDist = 10e10;
    4. int lIndex = -1;
    5.  
    6. // get nearest curve point by iterating over plot items, filtering for curves and calculating minimum distance
    7. const QwtPlotItemList& lPlotItemList = plot()->itemList();
    8. for (QwtPlotItemIterator lPlotItemIterator = lPlotItemList.begin(); lPlotItemIterator != lPlotItemList.end(); ++lPlotItemIterator)
    9. {
    10. if ((*lPlotItemIterator)->rtti() == QwtPlotItem::Rtti_PlotCurve)
    11. {
    12. PlotCurve *lTmpCurve = (PlotCurve*)(*lPlotItemIterator);
    13.  
    14. double lTmpDist;
    15. int lTmpIndex = lTmpCurve->closestPoint(pMousePos, &lTmpDist);
    16. if (lTmpDist < lDist && lTmpIndex > -1)
    17. {
    18. pPlotCurve = lTmpCurve;
    19. lDist = lTmpDist;
    20. lIndex = lTmpIndex;
    21. }
    22. }
    23. }
    24.  
    25. // check if mouse position is in tolerance
    26. if (pPlotCurve && lDist < _pix_tolerance_)
    27. {
    28. pYValue = pPlotCurve->y(lIndex);
    29. return true;
    30. }
    31. pPlotCurve = 0;
    32. return false;
    33. }
    To copy to clipboard, switch view to plain text mode 

    Within the trackerText() the call is..
    Qt Code:
    1. //..... some preparations
    2. // check if tracker text shall be displayed
    3. if(mTrackerValueEnable)
    4. {
    5. double lSelectedYValue = 0.0;
    6. PlotCurve* lSelectedCurve = 0;
    7. if (curveSelected(pMousePos, lSelectedCurve, lSelectedYValue))
    8. {
    9. lLabel.append(QString("\n%1").arg(QString::number(lSelectedYValue)));
    10. //..... whatever needed
    11. }
    12. }
    13. QwtText lText(lLabel);
    14. QColor lBackground(Qt::lightGray);
    15. lBackground.setAlpha(_text_background_alpha_);
    16. lText.setBackgroundBrush(QBrush(lBackground));
    17. return lText;
    To copy to clipboard, switch view to plain text mode 

    Regards
    Stefan

Similar Threads

  1. Check a point inside or outside a road?
    By kstking in forum Qt Programming
    Replies: 1
    Last Post: 15th October 2007, 18:48
  2. Moving the (0.0) point on the scene
    By maverick_pol in forum Qt Programming
    Replies: 1
    Last Post: 6th September 2007, 15:34

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.