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