I can't paste the whole code for the peak labels since it is quite long. If anyone is interested nonetheless:
https://cutenmr.svn.sourceforge.net/.../peaklabel.cpp
I will instead paste snippets of a minimal example I created. I already expected that it is caused by my (wrong) implementation.
My minimal example is a straight red line that is painted from the top of the canvas to the 0 position of my y-axis. The x-position is "3" in the unit of the x-axis. This is a screenshot of the (expected) result:
screen2.jpg
I mainly used the code from the cpupiemarker example for implementing my QwtPlotItem:
First, I get the QwtScaleMap from my PlotWidget (which is part of a parameters object that I can easily pass to other objects):
QwtScaleMap xMap = par->spectrum_plot->canvasMap(QwtPlot::xBottom);
QwtScaleMap yMap = par->spectrum_plot->canvasMap(QwtPlot::yLeft);
To copy to clipboard, switch view to plain text mode
Then the code for drawing the line:
p->save();
p
->drawLine
(QPointF(xMap.
transform(3),
0),
QPointF(xMap.
transform(3), yMap.
transform(0)));
p->restore();
p->save();
p->setPen(QColor(Qt::red));
p->drawLine(QPointF(xMap.transform(3), 0), QPointF(xMap.transform(3), yMap.transform(0)));
p->restore();
To copy to clipboard, switch view to plain text mode
And that's all you can find in my draw() function. Everything else is identical to the cpupiemarker example.
I attach the QwtPlotItem using this code:
peakLabel* pL = new peakLabel(par);
pL->attach(par->spectrum_plot);
peakLabel* pL = new peakLabel(par);
pL->attach(par->spectrum_plot);
To copy to clipboard, switch view to plain text mode
And the (unexpected) result of the exported image is:
export2.jpg
If you need other parts of the code to evaluate what my mistake is, just ask.
Many thanks
Bookmarks