Results 1 to 5 of 5

Thread: Tool tip in point of curve

  1. #1
    Join Date
    Sep 2011
    Posts
    13
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Tool tip in point of curve

    Hello!
    I have curve built by 100 points, how can i add tool tip with x and y to this points
    I try to use qwt symbol for this goal, but there is not method setToolTip
    In advance many thanks for your help!

  2. #2
    Join Date
    Feb 2011
    Location
    Bangalore
    Posts
    207
    Thanks
    20
    Thanked 28 Times in 27 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Tool tip in point of curve

    You can use QwtPlotPicker with QwtPicker::AlwaysOn to display text as you traverse the graph. See examples too.

  3. #3
    Join Date
    Sep 2011
    Posts
    13
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Tool tip in point of curve

    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?
    Last edited by ruzik; 12th October 2011 at 18:31.

  4. #4
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,244
    Thanked 860 Times in 809 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Tool tip in point of curve

    Quote Originally Posted by ruzik View Post
    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:

    Qt Code:
    1. class YourPlotPicker:: public QwtPlotPicker
    2. {
    3. ....
    4.  
    5. virtual QwtText trackerTextF( const QPointF &pos ) const
    6. {
    7. QwtPlotCurve *curve = NULL;
    8. double dist = 10e10;
    9. int index = -1;
    10.  
    11. const QwtPlotItemList& itmList = plot()->itemList();
    12. for ( QwtPlotItemIterator it = itmList.begin();
    13. it != itmList.end(); ++it )
    14. {
    15. if ( ( *it )->rtti() == QwtPlotItem::Rtti_PlotCurve )
    16. {
    17. QwtPlotCurve *c = static_cast<QwtPlotCurve *>( *it );
    18.  
    19. double d;
    20. int idx = c->closestPoint( pos, &d );
    21. if ( d < dist )
    22. {
    23. curve = c;
    24. index = idx;
    25. dist = d;
    26. }
    27. }
    28. }
    29.  
    30. QString text;
    31.  
    32. const int maxPixels = 10;
    33. if ( dist < maxPixels )
    34. {
    35. const QPointF pos = curve->sample( index );
    36. text.sprintf( "%.4f, %.4f", pos.x(), pos.y() );
    37. }
    38.  
    39. return QwtText( text );
    40. }
    41. };
    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

  5. #5
    Join Date
    Sep 2011
    Posts
    13
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Tool tip in point of curve

    Thank you for your help!


    Added after 50 minutes:


    Oh, function clossestPoint() dont work right!
    //http://hostingkartinok.com/image/01201110/54dfa7b8bb51489265f5c2141a17a7df.jpg
    For example look at this

    I checked: in the higher point distance is bigger, even if the cursor directly on the chart
    Last edited by ruzik; 23rd October 2011 at 12:23.

Similar Threads

  1. Replies: 3
    Last Post: 21st June 2011, 19:37
  2. Replies: 2
    Last Post: 5th May 2011, 06:53
  3. Replies: 2
    Last Post: 28th April 2011, 08:42
  4. Replies: 1
    Last Post: 9th December 2009, 17:14
  5. get the point of a fitted curve
    By giusepped in forum Qwt
    Replies: 1
    Last Post: 2nd January 2009, 04:03

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.