rotating a custom made symbol for QwtPlotCurve
hi
i have created a customized symbol by subclassing the QwtSymbol class and reimplementing the function,
Code:
{
public:
{
//shape of symbol( |___ )
QwtPainter::drawLine(painter, r.
bottomLeft(), r.
topLeft());
QwtPainter::drawLine(painter, r.
bottomLeft(), r.
bottomRight());
}
}
i want to rotate the symbols at some angle. but,i can not use the painter argument for doing this because its co-ordinates are not the co-ordinates of r(argument QRect).
how can i do this:confused:.
Re: rotating a custom made symbol for QwtPlotCurve
Quote:
i have created a customized symbol by subclassing the QwtSymbol class and reimplementing the function, ...
Note, that you can't customize the symbol of a marker/curve by subclassing, because it gets copied as QwtSymbol. Instead you have to subclass QwtPlotCurve and reimplement QwtPlotCurve::drawSymbols(). In Qwt 5.1-SVN ( svn co https://qwt.svn.sourceforge.net/svnroot/qwt/branches/qwt-5.1 ) you can subclass if you reimplement a QwtSymbol::copy() method.
Quote:
i want to rotate the symbols at some angle. but,i can not use the painter argument for doing this because its co-ordinates are not the co-ordinates of r(argument QRect).
The QRect is the rectangle ( position + size), where you have to paint your symbol. I'm not sure , what you mean by painter coordinates - maybe its translation ?
It depends on your type of symbol, if QPainter::rotate is the best way to paint it. If you want to use it you might have to set QPainter::translate to the position of your rotation.
HTH,
Uwe
Re: rotating a custom made symbol for QwtPlotCurve
hi
i have subclassed the QwtPlotCurve like this .
Code:
#include <QtGui>
#include "qwt_plot.h"
#include "qwt_plot_curve.h"
#include "qwt_valuelist.h"
#include "qwt_scale_div.h"
#include "qwt_symbol.h"
#include "qwt_painter.h"
{
public:
{
//painter->translate(r.topLeft());
//shape |_|__
QwtPainter::drawLine(painter, r.
bottomLeft(), r.
topLeft());
QwtPainter::drawLine(painter, r.
bottomLeft(), r.
bottomRight());
QwtPainter::drawLine(painter, r.
right()-r.
width()/2, r.
bottom(),
r.right()-r.width()/2, r.top());
}
};
{
public:
{
rect.
setSize(QwtPainter::metricsMap().
screenToLayout(symbol.
size()));
for (int i = from; i <= to; i++)
{
const int xi = xMap.transform(x(i));
const int yi = yMap.transform(y(i));
rect.
moveCenter(QPoint(xi, yi
));
painter
->setPen
(QPen(Qt
::blue));
feather f;
f.draw(painter, rect);
}
}
};
int main(int argc, char *argv[])
{
qwt
->setCanvasBackground
(QColor(Qt
::white));
//set scale for x-axis
qwt
->setAxisScale
(QwtPlot::xBottom,
13,
0);
qwt
->setAxisMaxMajor
(QwtPlot::xBottom,
24);
qwt
->setAxisMaxMinor
(QwtPlot::xBottom,
0);
//set scale for y-axis
qwt
->setAxisScale
(QwtPlot::yLeft,
0,
31);
//create data for curve
int MAX=12*30;
double x[MAX], y[MAX];
int k=1;
int l=1;
for (int i=0; i<MAX; i++)
{
x[i]=k;
y[i]=l;
k++;
if (k>12)
{
k=1;
l++;
}
}
//create symbol for curve
feather sym;
sym.setSize(30, 10);
//create curve , set symbol and data to curve
curve_data *cur=new curve_data;
cur->setSymbol(sym);
cur->setData(x, y, MAX);
cur->attach(qwt);
qwt->resize(800, 600);
qwt->show();
return a.exec();
}
i get the symbols , but i need to rotate individual symbols at different angles.
Re: rotating a custom made symbol for QwtPlotCurve
Quote:
i get the symbols , but i need to rotate individual symbols at different angles.
You know the position and the size of your symbol and you have control over the painting code.
What is missing ( maybe, that you don't know how to paint something rotated at all ) ?
Uwe
Re: rotating a custom made symbol for QwtPlotCurve
i have messed with the co-oridnates and now i have corrected it .
thank u.
also i have noticed that the subclassed function of QwtSymbol (draw ) is called twice ,
i have 360 symbols but the draw function is called 720 times.which i have found through global variable.
why is it called twice.
Re: rotating a custom made symbol for QwtPlotCurve
Quote:
why is it called twice.
It is called, whenever the content of your plot canvas has to be recreated ( QwtPlot::replot ). Use your debugger set a breakpoint in QwtPlotCurve::drawSymbols() and look at the stack, where you are.
Uwe