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:
marker->setLabelAlignment(Qt::AlignTop);
marker->attach(plot);
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);
To copy to clipboard, switch view to plain text mode
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);
double symbolHeight = abs(plot->invTransform(QwtPlot::yRight, marker->symbol().size().height()/2) - plot->invTransform(QwtPlot::yRight, 0) );
marker->setValue(x, y+symbolHeight);
To copy to clipboard, switch view to plain text mode
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
Bookmarks