Results 1 to 14 of 14

Thread: QwtPlotOverlay

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jun 2012
    Posts
    33
    Thanks
    6

    Default Re: QwtPlotOverlay

    About requirement:

    I have plots, on plots there is some amount of curves.
    I want to do next: when mouse enter plot i draw VLine (which is responsible for value X), than I for each curve calculate value of Y for current X and this value Y I need to show in position (X, Y)... And If I move mouse recalculate all...

    About QwtPlotPicker. I tried to do in this way, but I didnt find way to do for other plots QwtPlotPicker always visible ( QwtPlotPicker is visible as I understand when mouse cursor is on plot) and I didnt find way to change text of QwtPlotMarker and background of text ( I need to do background of text as color of curve).

    So I need to use as I undestand QwtPlotMarkers. But there is hard to do always replot to show QwtPlotMarkers, so I need to use something like QwtPlotOverlay....

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

    Default Re: QwtPlotOverlay

    Quote Originally Posted by carhun View Post
    I have plots, on plots there is some amount of curves.
    I want to do next: when mouse enter plot i draw VLine (which is responsible for value X), than I for each curve calculate value of Y for current X and this value Y I need to show in position (X, Y)... And If I move mouse recalculate all...
    Then QwtPlotPicker is exactly what you are looking for.

    All you need to do is to use the machine above and configure a vertical line as rubberband and enable the tracker text to AlwaysOn. Then overload QwtPlotPicker::trackerTextF where you calculate the corresponding y value for the curve ( or several curves ):

    Qt Code:
    1. class YourPicker: public QwtPlotPicker
    2. {
    3. virtual QwtText trackerTextF( const QPointF &pos ) const
    4. {
    5. return QwtPlotPicker::trackerTextF( x, findCurvePos( pos.x() );
    6. }
    7. }
    To copy to clipboard, switch view to plain text mode 

    How to implement findCurvePos in an effective way depends on the characteristics of your samples. F.e when your samples are ordered in x direction you could use some binary search algorithm ( if this is what you need I can post code lying on my disk ).

    Uwe

  3. #3
    Join Date
    Jun 2012
    Posts
    33
    Thanks
    6

    Default Re: QwtPlotOverlay

    Quote Originally Posted by Uwe View Post
    Then QwtPlotPicker is exactly what you are looking for.

    All you need to do is to use the machine above and configure a vertical line as rubberband and enable the tracker text to AlwaysOn. Then overload QwtPlotPicker::trackerTextF where you calculate the corresponding y value for the curve ( or several curves ):

    Qt Code:
    1. class YourPicker: public QwtPlotPicker
    2. {
    3. virtual QwtText trackerTextF( const QPointF &pos ) const
    4. {
    5. return QwtPlotPicker::trackerTextF( x, findCurvePos( pos.x() );
    6. }
    7. }
    To copy to clipboard, switch view to plain text mode 

    How to implement findCurvePos in an effective way depends on the characteristics of your samples. F.e when your samples are ordered in x direction you could use some binary search algorithm ( if this is what you need I can post code lying on my disk ).

    Uwe
    1. How for QwtPlotPicker I can draw more than one Text? I need for each curve text with value Y
    2. Can I control QwtPlotPicker? What I mean? I have 2 plots. than I want when I move QwtPlotPicker at plot 1 I need to move automatically move QwtPlotPicker at plot 2?
    3. How can I set position of VLine of Picker?
    4. As I can see I cant control text of QwtPlotPicker?... I dont see how I can do f.e. red backgroud and white letter for text of QwtPlotPicker...

    If I can do this, than this way suits me and I will thanks if U post code how to implement findCurvePos...

    And can U tell me why dont work QwtPlotMarker with QwtPlotOverlay like I show code above?

    Mb to do this task will be better to draw VLine by painter on QwtPlotOverlay and using QwtText for show value of Y for each curve? If it is more prefer way, can I draw QwtText not into rectangle? f.e. into circle or another shape that I want?

    F.e.:
    Qt Code:
    1. #ifndef WIDGET_H
    2. #define WIDGET_H
    3.  
    4. #include <QWidget>
    5. #include <QDebug>
    6.  
    7.  
    8. class Widget;
    9. class QwtPlot;
    10. class Picker;
    11.  
    12. class Widget : public QWidget
    13. {
    14. Q_OBJECT
    15.  
    16. public:
    17. explicit Widget(QWidget *parent = 0);
    18. ~Widget();
    19.  
    20. private:
    21. QVBoxLayout *m_layout;
    22.  
    23. QwtPlot *m_plot1;
    24. QwtPlot *m_plot2;
    25.  
    26. Picker *m_picker1; // for m_plot1
    27. Picker *m_picker2; // for m_plot2
    28. };
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. #include "widget.h"
    2.  
    3. #include <QWidget>
    4. #include <QVBoxLayout>
    5.  
    6. #include "plot.h"
    7.  
    8. #include "picker.h"
    9.  
    10. Widget::Widget(QWidget *parent) :
    11. QWidget(parent)
    12. {
    13. m_layout = new QVBoxLayout(this);
    14. m_layout->setMargin(0);
    15.  
    16. m_plot1 = new QwtPlot(this);
    17. m_plot2 = new QwtPlot(this);
    18.  
    19. m_layout->addWidget(m_plot1);
    20. m_layout->addWidget(m_plot2);
    21.  
    22. m_picker1 = new Picker(m_plot1->canvas());
    23. m_picker2 = new Picker(m_plot2->canvas());
    24.  
    25. connect(m_picker1, SIGNAL(moved(QPoint)),
    26. m_picker2, SLOT(slot_move(QPoint)));
    27.  
    28. connect(m_picker2, SIGNAL(moved(QPoint)),
    29. m_picker1, SLOT(slot_move(QPoint)));
    30.  
    31. setLayout(m_layout);
    32. }
    33.  
    34. Widget::~Widget()
    35. {
    36. }
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. #ifndef PICKER_H
    2. #define PICKER_H
    3.  
    4. #include <qwt/qwt_plot_picker.h>
    5.  
    6. class Picker : public QwtPlotPicker
    7. {
    8. Q_OBJECT
    9. public:
    10. explicit Picker(QWidget *parent = 0);
    11.  
    12. signals:
    13.  
    14. public slots:
    15. void slot_move(const QPoint &pos);
    16. };
    17.  
    18. #endif // PICKER_H
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. #include "picker.h"
    2.  
    3. #include <qwt/qwt_picker_machine.h>
    4.  
    5. Picker::Picker(QWidget *parent) :
    6. QwtPlotPicker(parent)
    7. {
    8. setRubberBandPen(QColor(Qt::magenta));
    9. setRubberBand(QwtPicker::VLineRubberBand);
    10. setTrackerPen(QColor(Qt::darkRed));
    11. setTrackerMode(QwtPicker::AlwaysOn);
    12. setTrackerFont(QFont("Helvetica"));
    13.  
    14. setStateMachine(new QwtPickerTrackerMachine);
    15. }
    16.  
    17. void Picker::slot_move(const QPoint &pos)
    18. {
    19. move(pos);
    20. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by carhun; 4th September 2012 at 14:32.

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

    Default Re: QwtPlotOverlay

    1. How for QwtPlotPicker I can draw more than one Text? I need for each curve text with value Y
    You need a text displaying one x and many y values - but not more than one text and it's up to you how to implement the trackerTextF() hook. Note that QwtText can do rich text ( even if it is not fast ), what means that you can even return tables or whatever.
    2. Can I control QwtPlotPicker? What I mean? I have 2 plots. than I want when I move QwtPlotPicker at plot 1 I need to move automatically move QwtPlotPicker at plot 2?
    I remember that I once posted an implementation for a cursor ( a moving vertical line ) implemented as picker, where the position is modified by application code. Check the archive.
    3. How can I set position of VLine of Picker?
    Answer is the same as for 2.
    4. As I can see I cant control text of QwtPlotPicker?... I dont see how I can do f.e. red backgroud and white letter for text of QwtPlotPicker...
    See QwtText::setBackgroundBrush(), QwtText::setBackgroundPen(), QwtText::setColor() - f.e used in spectrogram example.
    When using rich text ( even it is no fast ) each letter might have a different font and color ( see Qt docs ).

    QwtText != QString !!


    Uwe

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

    carhun (4th September 2012)

  6. #5
    Join Date
    Jun 2012
    Posts
    33
    Thanks
    6

    Default Re: QwtPlotOverlay

    I would like to clarify about text of QwtPlotPicker... It must be only ONE text, i.e. I can't display for QwtPlotPicker with help of reimplement of trackerTextF() something like: at (pos.x(), pox.y()) - text will be pos.y(), at (pos.x(), pos.y1()) - text will be pos.y1() ? For this I need use separately class QwtText? Am I rigth?

    About moving line as picker Ill try to find in examples, thanks.

    Mb I understand U wrong, but in what archive I need to find about implementation picker as moving vertical line by cursor? I tried to find in examples, there is only bode example use QwtPlotPicker, but not in way that i need...
    Last edited by carhun; 4th September 2012 at 15:46.

  7. #6
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,326
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows
    Thanked 880 Times in 828 Posts

    Default Re: QwtPlotOverlay

    I can't display for QwtPlotPicker with help of reimplement of trackerTextF() something like: at (pos.x(), pox.y()) - text will be pos.y(), at (pos.x(), pos.y1()) - text will be pos.y1() ?
    QwtText is a QString with additional attributes - how it is built and what information you want to display is completely up to you. You could return the name of your grandma if you want to.
    Mb I understand U wrong, but in what archive I need to find about implementation picker as moving vertical line by cursor?
    The archive of this forum or the Qwt mailing list - I can't remember, but I had posted a full implementation somewhere in the last year.

    Uwe

  8. #7
    Join Date
    Jun 2012
    Posts
    33
    Thanks
    6

    Default Re: QwtPlotOverlay

    Quote Originally Posted by Uwe View Post
    QwtText is a QString with additional attributes - how it is built and what information you want to display is completely up to you. You could return the name of your grandma if you want to.
    I dont undestand for what I need to return the name of grandma... Can U explain more detail?
    I want (red color) to get Untitled.png

    The archive of this forum or the Qwt mailing list - I can't remember, but I had posted a full implementation somewhere in the last year.
    I coudn't find too. All that I found was to do with help of QwtPlotMarker(http://sourceforge.net/mailarchive/m...sg_id=19655286) or with help of QwtPlotTrackerMachine (this is not exactly what I need - http://sourceforge.net/mailarchive/m...sg_id=24922429)

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

    Default Re: QwtPlotOverlay

    As you are not the first one who is asking for a "curve tracker" and I have the code on my disk I will add it as example to SVN trunk.

    Uwe

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

    carhun (6th September 2012)

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

    Default Re: QwtPlotOverlay

    O.k. now you find a new example "playground/curvetracker" in SVN trunk. It is not exactly your use case as it draws one tracker label ( with the positions of all curves ) aligned to the first curve. If you want to have different labels for each curve simply use several curve picker, where only one of them has the vertical line enabled ( of course you need to modify the picker a bit then ).

    The tracker shows a multicolored text, where the color is taken from the corresponding curve pen. Take this as an example how to use rich text.

    The tracker uses a new method qwtUpperSampleIndex, that performs a binary search on the curve points. If you want to use Qwt 6.0 you can simply copy the template into your application code. Beside this the CurveTracker should be compatible with Qwt 6.0.

    Please check if the way how the template is declared in qwt_series_data.h is compatible with Windows compilers ( when you are on this system ).

    HTH,
    Uwe

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

    carhun (10th September 2012)

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
  •  
Qt is a trademark of The Qt Company.