Results 1 to 4 of 4

Thread: Qwt question

  1. #1
    Join Date
    Aug 2007
    Posts
    264
    Thanks
    26
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Qwt question

    I have some data in my app using Qwt Plot and i want to measure some delta values using my mouse in my plot.

    eg:
    given:
    point 1 (1,3)
    point 2 (2,4)
    point 3 (3,1)

    now if i point my mouse to point 1 (click) then point 2 (click)

    then i should show:

    delta x = 1 and delta y = 1
    how can i implement this in Qwt? please enlightened me

    baray98

  2. #2
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,181
    Thanked 842 Times in 791 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Qwt question

    Have a look at the CanvasPicker class in the event_filter example. It shows how to find a point from a mouse click. But note, that the implementation is slow for curves with many points.

    But if I had to implement a distance measurement I would use a tailored QwtPlotPicker object, because of its tracker text.

    Uwe

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

    baray98 (25th November 2007)

  4. #3
    Join Date
    Aug 2007
    Posts
    264
    Thanks
    26
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Qwt question

    Hi uwe,

    I did follow your advise and pop up a widget showing my delta at the end of my selction

    I connected signal QwtPlotPicker::selected(const QwtDoubleRect &) to trigger my class to display the delta.

    I wanted to modify this ,instead of showing delta at the end of my selecetion I want to show the delta while the user is dragging a selection , its like overiding the the tracker text how can i do this? i tried re-implementing the trackerText but did not work .

    baray98

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

    Default Re: Qwt question

    I found some old code on my disk, maybe it helps:

    Qt Code:
    1. class DistancePicker : public QwtPlotPicker
    2. {
    3. public:
    4. DistancePicker(QwtPlotCanvas *);
    5.  
    6. protected:
    7. virtual void drawRubberBand(QPainter *) const;
    8. virtual QwtText trackerText(const QwtDoublePoint &) const;
    9. };
    10.  
    11. DistancePicker::DistancePicker(QwtPlotCanvas* canvas):
    12. QwtPlotPicker(canvas)
    13. {
    14. /*
    15.   We don't have a picker for a line, but the rectangle
    16.   selection is also a selection of 2 points. So all we
    17.   have to do is to paint a line rubberband.
    18.   */
    19. setSelectionFlags(QwtPicker::RectSelection);
    20. setRubberBand(PolygonRubberBand);
    21. setTrackerMode(QwtPicker::ActiveOnly);
    22.  
    23. // Disable keyboard handling
    24. setKeyPattern(QwtEventPattern::KeySelect1, Qt::Key_unknown);
    25. setKeyPattern(QwtEventPattern::KeySelect2, Qt::Key_unknown);
    26. }
    27.  
    28. void DistancePicker::drawRubberBand(QPainter *painter) const
    29. {
    30. painter->drawPolygon(selection());
    31. }
    32.  
    33. QwtText DistancePicker::trackerText(const QwtDoublePoint &) const
    34. {
    35. const QwtPolygon &polygon = selection();
    36. if ( polygon.size() != 2 )
    37. return QwtText();
    38.  
    39. const QLineF line(invTransform(polygon[0]), invTransform(polygon[1]));
    40.  
    41. QwtText text( QString::number(line.length()) );
    42.  
    43. QColor bg(Qt::white);
    44. bg.setAlpha(180);
    45. text.setBackgroundBrush(QBrush(bg));
    46.  
    47. return text;
    48. }
    To copy to clipboard, switch view to plain text mode 

    Uwe

Similar Threads

  1. QWT fails in debug build
    By steg90 in forum Qwt
    Replies: 1
    Last Post: 11th November 2011, 06:53
  2. QWT introduction
    By nitriles in forum Qwt
    Replies: 4
    Last Post: 28th September 2007, 10:48
  3. Qwt 5.0.2
    By Uwe in forum Qt-based Software
    Replies: 1
    Last Post: 20th September 2007, 18:21
  4. How to upgrade Qwt 5.0.1 to Qwt 5.0.2
    By luffy27 in forum Qwt
    Replies: 1
    Last Post: 15th July 2007, 19:55
  5. use interesting QWT Library with QT3.X
    By raphaelf in forum Qwt
    Replies: 2
    Last Post: 23rd January 2006, 11:24

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.