Sharing on QwtPlotPicker showing values of dual Y axes
I have a plot with both Y axes enabled, but find the picker by default will only show value of either one.
After a while I have figured out a solution, though may not be elegant. :o
At the beginning I thought of having two QwtPlotPicker showing each axis but then it turns out their labels overlap and I could not control the label position.
So I came up with another thought: Modify what the picker displays on its label.
I first sub-class QwtPlotPicker.
I was thinking about overriding updateDisplay() then draw the label manually.
However after reading the source I know that I could override trackerText() which is a virtual function.
In the class header:
For the implementation of trackerText(), all I need is to return a text with both Y axes value but the problem is how.
A picker must know also the Y value of the other picker, so I passed a reference of the other picker in the constructor.
In trackerText(), I get the Y value of alt_picker by calling its trackerText() function.
QwtPlotPicker::trackerText() is protected so I instead call QwtPicker::trackerText().
I actually re-organized the text content of both picker but here is a simple append solution.
Code:
QwtText const &alt_text
= ((QwtPicker*)(alt_picker
))->trackerText
(alt_picker
->trackerPosition
());
QString alt_y
(alt_text.
text().
split(",").
at(1));
I do not know if there is a better way and I would love to know.
At least it works for me and it is not that cumbersome. :p
Re: Sharing on QwtPlotPicker showing values of dual Y axes
Quote:
Originally Posted by
davey
For the implementation of trackerText(), all I need is to return a text with both Y axes value but the problem is how.
You can use the canvas maps:
Code:
virtual QwtText YourPicker
::trackerText(const QwtDoublePoint
&pos
) const {
double y2 = plot()->canvasMap(axis).invTransform(p.y());
...
}
In your special situation, where you simple append the second y value to the text you could also do the following:
Code:
{
double y2 = plot()->canvasMap(axis).transform(p.y());
text += ...
return text:
}
Uwe