Results 1 to 6 of 6

Thread: Help: How to draw markers on plot?

  1. #1
    Join Date
    Feb 2009
    Posts
    51
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Help: How to draw markers on plot?

    Hi,

    I asked this question before but did not get the answer so I try again. Could someone help me on how to draw simple marker on my plot at a given point x, y? Something like an "X" or "+"?

    Any help is greatly appreciated.
    Sincerely,

    Wieland J.

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

    Default Re: Help: How to draw markers on plot?

    Quote Originally Posted by jwieland View Post
    I asked this question before but did not get the answer so I try again. Could someone help me on how to draw simple marker on my plot at a given point x, y? Something like an "X" or "+"?
    Surprisingly a marker is displayed by a class called QwtPlotMarker.
    Did you ever look into the docs or the examples, that are included in the Qwt package ?

    Uwe

  3. #3
    Join Date
    Feb 2009
    Posts
    51
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Help: How to draw markers on plot?

    Quote Originally Posted by Uwe View Post
    Surprisingly a marker is displayed by a class called QwtPlotMarker.
    Did you ever look into the docs or the examples, that are included in the Qwt package ?

    Uwe
    Thanks, Uwe. No, I have not looked into QwtPlotMarker. Will do
    Sincerely,

    Wieland J.

  4. #4
    Join Date
    Nov 2009
    Posts
    94
    Thanks
    14
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Question Re: Help: How to draw markers on plot?

    Hello,

    I'm rather frustrated because I have been trying to draw QwtPlotMarker and drag them on the plot for one week now and still have no successful results. I need your help!

    1) First I have subclassed the QwtPlotMarker class and wrote my own class:

    point.h
    Qt Code:
    1. #include <qpainter.h>
    2. #include <qwt_plot_grid.h>
    3. #include <qwt_plot_canvas.h>
    4. #include <qwt_plot_layout.h>
    5. #include <qwt_double_interval.h>
    6. #include <qwt_painter.h>
    7. #include <qwt_plot_item.h>
    8. #include <qwt_plot_marker.h>
    9. #include <stdlib.h>
    10.  
    11. class PointItem: public QObject, public QwtPlotMarker
    12. {
    13. Q_OBJECT
    14.  
    15. public:
    16.  
    17. PointItem(QwtDoubleRect rect);
    18.  
    19.  
    20. QwtDoubleRect boundingRect() const;
    21.  
    22. void draw(QPainter *painter,
    23. const QwtScaleMap &xMap, const QwtScaleMap &yMap, const QRect &) const;
    24. protected:
    25. virtual void itemChanged();
    26.  
    27. private:
    28. QwtDoubleRect d_rect;
    29. };
    To copy to clipboard, switch view to plain text mode 

    point.cpp
    Qt Code:
    1. #include "point.h"
    2. #include <iostream>
    3.  
    4. PointItem::PointItem(QwtDoubleRect rect):d_rect(rect){
    5. //setZ(20);
    6. }
    7.  
    8. QwtDoubleRect PointItem::boundingRect() const{
    9. return d_rect;
    10. }
    11.  
    12. void PointItem::itemChanged(){
    13. std::cout << "in ItemChanged() \n";
    14. }
    15.  
    16. void PointItem::draw(QPainter *painter,
    17. const QwtScaleMap &xMap, const QwtScaleMap &yMap, const QRect &) const
    18. {
    19. if ( d_rect.isValid() )
    20. {
    21. const QRect rect = transform(xMap, yMap, d_rect);
    22. painter->setPen(QColor(Qt::black));
    23. painter->setBrush(QBrush(QColor(Qt::white)));
    24. QwtPainter::drawEllipse(painter, rect);
    25. }
    26. }
    To copy to clipboard, switch view to plain text mode 

    If I then execute the below standing line codes, then I get drawn a big white circle on my plot, so it is ok. But if I use a PlotPicker on it, it cannot be moved/dragged on the plot;
    Qt Code:
    1. PointItem *point = new PointItem(QwtDoubleRect(0,0,000.2,000.2));
    2. point->attach(this);
    To copy to clipboard, switch view to plain text mode 

    2) After that I have tried to use the standard QwtPlotMarker and QwtSymbol to put a point/ circle onto the plot, but it does not appear at all (see code below). Do I have to add something to the code?
    Qt Code:
    1. QwtSymbol *symb = new QwtSymbol();
    2. symb->setBrush(QBrush(Qt::red, Qt::SolidPattern));
    3. symb->setStyle(QwtSymbol::Ellipse);
    4. symb->setSize(0.5,0.5);
    5. mark->setSymbol(*symb);
    6. mark->setXValue(0.5);
    7. mark->setYValue(0.5);
    8. mark->attach(this);
    To copy to clipboard, switch view to plain text mode 

    Thank you for your help.

    best regards

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

    Default Re: Help: How to draw markers on plot?

    The symbol size is integer based ( something in pixels), so setting a size of (0.5, 0.5) is rounded to (0, 0). And don't expect to see much of a circle, when the size is below several pixels.

    Uwe

  6. #6
    Join Date
    Nov 2009
    Posts
    94
    Thanks
    14
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Help: How to draw markers on plot?

    Quote Originally Posted by Uwe View Post
    The symbol size is integer based ( something in pixels), so setting a size of (0.5, 0.5) is rounded to (0, 0). And don't expect to see much of a circle, when the size is below several pixels.

    Uwe
    Thank you Uwe,

    Now I have changed the size to (10,10) and the circle is shown now, but it still cannot be dragged. Does using the standard QwtPickerPlot allows to dragg plot items or does it only provide the selection? I use now:
    Qt Code:
    1. // create QwtPlotPicker to allow user moving the points on the plot
    2.  
    3. picker = new QwtPlotPicker(QwtPlot::xBottom, QwtPlot::yLeft,
    4. QwtPicker::PointSelection | QwtPicker::DragSelection,
    5. QwtPlotPicker::CrossRubberBand, QwtPicker::AlwaysOn,
    6. this->canvas());
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Put plot axis out of the plot
    By KosyakOFF in forum Qwt
    Replies: 7
    Last Post: 21st June 2013, 14:36
  2. Replies: 6
    Last Post: 21st September 2009, 11:55
  3. Replies: 1
    Last Post: 9th April 2009, 15:54
  4. Spectrogram Plot Hints
    By shargath in forum Qwt
    Replies: 2
    Last Post: 25th February 2009, 12:11
  5. Replies: 7
    Last Post: 22nd September 2008, 23:05

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.