PDA

View Full Version : Help: How to draw markers on plot?



jwieland
19th September 2009, 20:56
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.

Uwe
20th September 2009, 08:15
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

jwieland
20th September 2009, 22:58
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 :)

rambo83
24th November 2009, 07:57
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>

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;
};

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";
}

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);
}
}


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);

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?

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);

Thank you for your help.

best regards

Uwe
24th November 2009, 10:56
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

rambo83
24th November 2009, 11:22
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:

// create QwtPlotPicker to allow user moving the points on the plot

picker = new QwtPlotPicker(QwtPlot::xBottom, QwtPlot::yLeft,
QwtPicker::PointSelection | QwtPicker::DragSelection,
QwtPlotPicker::CrossRubberBand, QwtPicker::AlwaysOn,
this->canvas());