Results 1 to 12 of 12

Thread: Selecting QwtPlotCurve from QwtPlot

  1. #1

    Default Selecting QwtPlotCurve from QwtPlot

    Hello there,
    I want to have a window that contains a QTable and a QwtPlot and when I select a curve with the mouse, the points of the curve will appear at the QTable.
    The problem that I have is that I don't know how to select a curve. I have seen the example (event_filter) that just selects points not the whole curve.
    Do you have any suggestions?
    Thank you in advance

  2. #2
    Join Date
    Jun 2013
    Posts
    56
    Thanks
    4
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Selecting QwtPlotCurve from QwtPlot

    this may be a way: you can use a point picker or subclass it to get the current mouse position, and code a function to judge whether the position is on one of the segments of one of the curves.

  3. #3
    Join Date
    Jun 2012
    Posts
    173
    Thanks
    48
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Selecting QwtPlotCurve from QwtPlot

    the Even_filter example is all what you need,
    in this example it does select the curve, in the select method,

    in these lines:

    Qt Code:
    1. for ( QwtPlotItemIterator it = itmList.begin();
    2. it != itmList.end(); ++it )
    3. {
    4. if ( ( *it )->rtti() == QwtPlotItem::Rtti_PlotCurve )
    5. {
    6. QwtPlotCurve *c = static_cast<QwtPlotCurve *>( *it ); /// c is the curve you clicked on
    7.  
    8. double d;
    9. int idx = c->closestPoint( pos, &d );
    10. if ( d < dist )
    11. {
    12. curve = c;
    13. index = idx;
    14. dist = d;
    15. }
    16. }
    To copy to clipboard, switch view to plain text mode 

  4. #4

    Default Re: Selecting QwtPlotCurve from QwtPlot

    Quote Originally Posted by Nicho View Post
    this may be a way: you can use a point picker or subclass it to get the current mouse position, and code a function to judge whether the position is on one of the segments of one of the curves.
    Yes this is my my question, how to get the segments of the curve, in order to check them with mouse position

    Quote Originally Posted by jesse_mark View Post
    the Even_filter example is all what you need,
    in this example it does select the curve, in the select method,

    in these lines:

    Qt Code:
    1. for ( QwtPlotItemIterator it = itmList.begin();
    2. it != itmList.end(); ++it )
    3. {
    4. if ( ( *it )->rtti() == QwtPlotItem::Rtti_PlotCurve )
    5. {
    6. QwtPlotCurve *c = static_cast<QwtPlotCurve *>( *it ); /// c is the curve you clicked on
    7.  
    8. double d;
    9. int idx = c->closestPoint( pos, &d );
    10. if ( d < dist )
    11. {
    12. curve = c;
    13. index = idx;
    14. dist = d;
    15. }
    16. }
    To copy to clipboard, switch view to plain text mode 
    In the example the itmList has all the QwtPlotItems and with rtti() it checks if a QwtPlotItem is a QwtPlotCurve. So I don't think this is the solution. It is the beginning though.

  5. #5
    Join Date
    Jun 2012
    Posts
    173
    Thanks
    48
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Selecting QwtPlotCurve from QwtPlot

    yeah you right it check if it a curve or not, then checking the closest point

    go more done using the curve closest point and distance;
    u can fined your selected curve.
    Qt Code:
    1. if ( curve && dist < 10 ) // 10 pixels tolerance
    2. {
    3. d_selectedCurve = curve;
    4. d_selectedPoint = index;
    5. showCursor( true );
    6. }
    To copy to clipboard, switch view to plain text mode 

  6. #6

    Default Re: Selecting QwtPlotCurve from QwtPlot

    You are also right, but still this finds only when the user clicks on a point. I'd like to select the line between the points as well

  7. #7
    Join Date
    Jun 2012
    Posts
    173
    Thanks
    48
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Selecting QwtPlotCurve from QwtPlot

    well, this way its all depends :
    - the Distance Between different Points on a curve(DBP),
    - the Distance Between the different Curves(DBCs).

    you may just need to use better tolerance distance to meet your needs. (if DBP is less than the DBCs ).

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

    Default Re: Selecting QwtPlotCurve from QwtPlot

    Also have a look at the curvetracker example - maybe you find some interesting code snippet there too.

    Uwe

  9. #9

    Default Re: Selecting QwtPlotCurve from QwtPlot

    Thank you for your answers, I used a mathematical equation that finds if the mouse point is on the line between the curves

  10. #10
    Join Date
    Jul 2013
    Posts
    72
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: Selecting QwtPlotCurve from QwtPlot

    I have looked into the curvetracker example and practiced . However , it can only locate the point on a straight line between two points without deviation . Deviation comes while the curve is set myplot->setCurveAttribute(QwtPlotCurve::Fitted) .

    Any idea to fix this problem?
    Thanks in advance !!

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

    Default Re: Selecting QwtPlotCurve from QwtPlot

    Well, the fitter creates temporary points in paint device coordinates, that are not known to the picker. What you could do is to apply the spline interpolation to your points in plot coordinates ( using QwtSplineCurveFitter::fitCurve() manually ) passing the interpolated points instead. The curvetracker code works out of the box - but of course this is a different type of interpolation.

    If you don't want to do this you could overload QwtSplineFitter::fitCurve() and store the interpolated points:

    Qt Code:
    1. class YourSplineFitter: public QwtSplineFitter
    2. {
    3. public:
    4. virtual QPolygonF fitCurve( const QPolygonF &points ) const
    5. {
    6. mInterpolatedPoints = QwtSplineFitter::fitCurve( points );
    7. return mInterpolatedPoints;
    8. }
    9.  
    10. ...
    11. private:
    12. QPolygonF mInterpolatedPoints;
    13. };
    To copy to clipboard, switch view to plain text mode 

    Then the CurveTracker can be implemented using mInterpolatePoints.

    HTH,
    Uwe

  12. The following user says thank you to Uwe for this useful post:

    lwz (23rd July 2013)

  13. #12
    Join Date
    Jul 2013
    Posts
    72
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: Selecting QwtPlotCurve from QwtPlot

    Thanks ,it works much better

Similar Threads

  1. Replies: 8
    Last Post: 9th February 2014, 12:37
  2. Replies: 1
    Last Post: 11th May 2012, 08:02
  3. Replies: 1
    Last Post: 13th July 2011, 08:55
  4. Selecting a QwtPlotCurve object.
    By mah_singh1 in forum Qwt
    Replies: 1
    Last Post: 21st April 2009, 07:12
  5. Replies: 2
    Last Post: 25th March 2008, 14:36

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.