PDA

View Full Version : Alignment of QwtSymbol



FelixB
7th January 2011, 08:39
Good morning,

I have a very short question with a long explanation. So, here's the question:

So, here is my question: is it possible to change the alignment of a QwtSymbol used in a QwtPlotMarker? if not, is it possible to create a custom symbol (e.g. a polygon)?


I'm using a QwtPlotMarker with a symbol (DTriangle) to point on a curve:


QwtPlotMarker* marker = new QwtPlotMarker();
marker->setAxis(QwtPlot::xTop, QwtPlot::yRight);
marker->setSymbol(QwtSymbol(QwtSymbol::DTriangle, QBrush(m_curve->pen().color().lighter()), QPen(m_curve->pen().color()), QSize(9,11)));
marker->setLabelAlignment(Qt::AlignTop);
marker->attach(plot);

I get the x/y-coordinates of the point I want to point on. But, if I set marker->setValue(x,y), the triangle is painted with x/y at it's center. I'd like to have it top-aligned, so that the lower corner is at (x,y). My first thought was: shift y by transformed size of the symbol:


double symbolHeight = abs(plot->invTransform(QwtPlot::yRight, marker->symbol().size().height()/2) - plot->invTransform(QwtPlot::yRight, 0) );
marker->setValue(x, y+symbolHeight);

that works - until I zoom in or out. Then, the triangle is too high or too low. This is also clear: the fixed pixel size of the symbol was translated into yValues. When I zoom, the ratio pixel/values changes and so does the distance between marker pos and curve. I know, I could recalculate the marker's position each time I zoom, but maybe there's a better solution...


thanks!
Felix

Uwe
11th January 2011, 06:42
Overload QwtSymbol ( QwtSymbol::drawSymbols in Qwt 6, QwtSymbol::draw in Qwt 5 ) do your translation and call the baseclass.

Uwe

FelixB
11th January 2011, 08:40
that's a good idea, thank you!