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
#include <qpainter.h>
#include <qwt_plot_grid.h>
#include <qwt_plot_canvas.h>
#include <qwt_plot_layout.h>
#include <qwt_double_interval.h>
#include <qwt_painter.h>
#include <qwt_plot_item.h>
#include <qwt_plot_marker.h>
#include <stdlib.h>
{
Q_OBJECT
public:
PointItem(QwtDoubleRect rect);
QwtDoubleRect boundingRect() const;
protected:
virtual void itemChanged();
private:
QwtDoubleRect d_rect;
};
#include <qpainter.h>
#include <qwt_plot_grid.h>
#include <qwt_plot_canvas.h>
#include <qwt_plot_layout.h>
#include <qwt_double_interval.h>
#include <qwt_painter.h>
#include <qwt_plot_item.h>
#include <qwt_plot_marker.h>
#include <stdlib.h>
class PointItem: public QObject, public QwtPlotMarker
{
Q_OBJECT
public:
PointItem(QwtDoubleRect rect);
QwtDoubleRect boundingRect() const;
void draw(QPainter *painter,
const QwtScaleMap &xMap, const QwtScaleMap &yMap, const QRect &) const;
protected:
virtual void itemChanged();
private:
QwtDoubleRect d_rect;
};
To copy to clipboard, switch view to plain text mode
point.cpp
#include "point.h"
#include <iostream>
PointItem::PointItem(QwtDoubleRect rect):d_rect(rect){
//setZ(20);
}
QwtDoubleRect PointItem::boundingRect() const{
return d_rect;
}
void PointItem::itemChanged(){
std::cout << "in ItemChanged() \n";
}
{
if ( d_rect.isValid() )
{
const QRect rect
= transform
(xMap, yMap, d_rect
);
painter
->setPen
(QColor(Qt
::black));
}
}
#include "point.h"
#include <iostream>
PointItem::PointItem(QwtDoubleRect rect):d_rect(rect){
//setZ(20);
}
QwtDoubleRect PointItem::boundingRect() const{
return d_rect;
}
void PointItem::itemChanged(){
std::cout << "in ItemChanged() \n";
}
void PointItem::draw(QPainter *painter,
const QwtScaleMap &xMap, const QwtScaleMap &yMap, const QRect &) const
{
if ( d_rect.isValid() )
{
const QRect rect = transform(xMap, yMap, d_rect);
painter->setPen(QColor(Qt::black));
painter->setBrush(QBrush(QColor(Qt::white)));
QwtPainter::drawEllipse(painter, rect);
}
}
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;
PointItem *point = new PointItem(QwtDoubleRect(0,0,000.2,000.2));
point->attach(this);
PointItem *point = new PointItem(QwtDoubleRect(0,0,000.2,000.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?
symb
->setBrush
(QBrush(Qt
::red, Qt
::SolidPattern));
symb->setSize(0.5,0.5);
mark->setSymbol(*symb);
mark->setXValue(0.5);
mark->setYValue(0.5);
mark->attach(this);
QwtPlotMarker *mark = new QwtPlotMarker();
QwtSymbol *symb = new QwtSymbol();
symb->setBrush(QBrush(Qt::red, Qt::SolidPattern));
symb->setStyle(QwtSymbol::Ellipse);
symb->setSize(0.5,0.5);
mark->setSymbol(*symb);
mark->setXValue(0.5);
mark->setYValue(0.5);
mark->attach(this);
To copy to clipboard, switch view to plain text mode
Thank you for your help.
best regards
Bookmarks