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.
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:
protected:
protected:
virtual QwtText trackerText(QPoint const &pos) const;
To copy to clipboard, switch view to plain text mode
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.
protected:
protected:
QwtPlotPicker *alt_picker;
To copy to clipboard, switch view to plain text mode
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.
QwtText const &alt_text
= ((QwtPicker*)(alt_picker
))->trackerText
(alt_picker
->trackerPosition
());
QString alt_y
(alt_text.
text().
split(",").
at(1));
QwtText const &alt_text = ((QwtPicker*)(alt_picker))->trackerText(alt_picker->trackerPosition());
QString alt_y(alt_text.text().split(",").at(1));
QString result(QwtPlotPicker::trackerText(pos).text() + ", " + alt_y);
return QwtText(result);
To copy to clipboard, switch view to plain text mode
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.
Bookmarks