Results 1 to 8 of 8

Thread: Distance measuring in plot.

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1

    Default Distance measuring in plot.

    Hi,

    I'm trying to create a distance measure tool, that will display the delta X and delta Y values of 2 points within the plot, and draw a line between these two points.

    I started out with some old code from (http://www.qtcentre.org/archive/index.php/t-10367.html). Some changes were needed to get it running in Qwt6.

    Qt Code:
    1. class DistancePicker : public QwtPlotPicker
    2. {
    3. public:
    4. DistancePicker( QwtPlotCanvas * canvas )
    5. :QwtPlotPicker( canvas )
    6. {
    7. setStateMachine( new QwtPickerClickRectMachine );
    8. setRubberBand( PolygonRubberBand );
    9. setTrackerMode( QwtPicker::ActiveOnly );
    10. }
    11.  
    12. protected:
    13. virtual void drawRubberBand(QPainter* painter) const
    14. {
    15. painter->drawPolygon( selection() );
    16. }
    17.  
    18. virtual QwtText trackerText (const QPoint& pos) const
    19. {
    20. const QPolygon& polygon = selection();
    21.  
    22. if ( polygon.size() != 2 )
    23. {
    24. return QwtText();
    25. }
    26.  
    27. const QLineF line(invTransform(polygon[0]), invTransform(polygon[1]));
    28.  
    29. QwtText text( QString::number(line.length()) );
    30.  
    31. QColor bg(Qt::white);
    32. bg.setAlpha(180);
    33. text.setBackgroundBrush(QBrush(bg));
    34.  
    35. return text;
    36. }
    37. };
    To copy to clipboard, switch view to plain text mode 

    While this seems to be working good, i do have a few problems with it.
    1) Depending on where you move the second selection for the measurement, the measurement picker text runs through the default picker that that always displays the current x,y position. Is there something to do about that ?
    2) When we zoom in to the plot, just after releasing the mouse for the zoom action, the plot zooms in to new selection, and then automagically a measurement is started.
    Is it possible to do measurements only when user presses space bar for instance ?

    Thanks for any help !

    TJ
    Last edited by thejester; 5th May 2011 at 08:47.

Similar Threads

  1. Increase the distance between two lines in QTextEdit
    By ansar in forum Qt Programming
    Replies: 1
    Last Post: 30th March 2010, 23:08
  2. Distance Transform on a QImage
    By Franckesh in forum Qt Programming
    Replies: 2
    Last Post: 20th January 2010, 09:58
  3. pixel distance of gaps in scaleWidget
    By KosyakOFF in forum Qwt
    Replies: 1
    Last Post: 3rd November 2008, 11:02
  4. Double click distance
    By jbd in forum Qt Programming
    Replies: 3
    Last Post: 28th December 2007, 23:13
  5. QProgress Bar-Time Measuring
    By aegis in forum Qt Programming
    Replies: 4
    Last Post: 13th May 2007, 17:47

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.