Results 1 to 5 of 5

Thread: Printing Values of the mouse position in a graph

  1. #1
    Join Date
    Sep 2008
    Location
    Chennai
    Posts
    36
    Thanks
    5
    Thanked 1 Time in 1 Post
    Qt products
    Qt3
    Platforms
    Unix/X11

    Question Printing Values of the mouse position in a graph

    I have a graph with X and Y scale of (0-100, 0-100), the graph is simple sine function. I want to get the values of the axis point, where the mouse button is clicked. I am able to get the widget mouse position, but not able to get the actual graph position values(the sine function values).
    Is it possible to get the values ?? is it possible to display those values as a tooltip ???

    Thanks in advance .......

  2. #2
    Join Date
    Mar 2009
    Posts
    98
    Thanks
    3
    Thanked 9 Times in 9 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Printing Values of the mouse position in a graph

    See the bode example.

  3. #3
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,311
    Thanked 879 Times in 827 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Printing Values of the mouse position in a graph

    Qt Code:
    1. class YourPicker: public QwtPlotPicker
    2. {
    3. virtual QwtText QwtPlotPicker::trackerText(const QPoint &pos) const
    4. {
    5. const QwtDoublePoint p = invTransform(pos);
    6. const QwtDoublePoint curvePos(p.x(), ::sin(p.x());
    7.  
    8. QString text;
    9. if ( qAbs(pos.y() - transform(curvePos).y() ) < 4 )
    10. text.sprintf("%.4f, %.4f", curvePos.x(), curvePos.y());
    11.  
    12. return text;
    13. }
    14. };
    To copy to clipboard, switch view to plain text mode 

    Then use your picker like in the bode or like in the spectrogram example.

    HTH,
    Uwe

  4. #4
    Join Date
    Sep 2008
    Location
    Chennai
    Posts
    36
    Thanks
    5
    Thanked 1 Time in 1 Post
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Re: Printing Values of the mouse position in a graph

    Hi Uwe ...
    Actually I put the sin function as an example, I just want to display the values where ever (on the curve) the mouse is clicked, how it is possible ..... is it possible to display those value as a mouse tool tip ???

  5. #5
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,311
    Thanked 879 Times in 827 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Printing Values of the mouse position in a graph

    Actually I put the sin function as an example, I just want to display the values where ever (on the curve) the mouse is clicked, how it is possible .....
    Replace the code by something that finds the next point in your data. You can try to use QwtPlotCurve::closestPoint(), but this implementation is slow for many points. Then you will need something spatial indexed like a quadtree.
    is it possible to display those value as a mouse tool tip ???
    What about reading the answers you already got ?

    Uwe

Similar Threads

  1. Word at mouse click position in QGraphicsTextItem
    By pherthyl in forum Qt Programming
    Replies: 2
    Last Post: 3rd November 2008, 04:56
  2. Mouse position on screen
    By Nippler in forum Qt Programming
    Replies: 3
    Last Post: 7th August 2008, 14:22
  3. grabbing position of mouse
    By safknw in forum Qt Programming
    Replies: 10
    Last Post: 28th June 2008, 15:00
  4. Enter event mouse position
    By bunjee in forum Qt Programming
    Replies: 9
    Last Post: 7th May 2008, 18:53
  5. Qt4.1 Mouse Position & Scaling
    By Paul Drummond in forum Qt Programming
    Replies: 1
    Last Post: 16th February 2006, 19:02

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.