问题
By default, Qwt
displays large numbers on the axis in scientific notation:
For my application, I'd really like to turn this off OR reformat the labels. Looking through the class documentation, it doesn't seem like any of the QwtScale
classes have an option for this. Can this behavior be implemented by deriving a new class? If so, which class should it be derived from and which members would need to be overloaded?
回答1:
Thanks to bkausbk, I was able to come up with this modified QwtScaleDraw
:
class QScaleDraw : public QwtScaleDraw
{
public:
explicit QScaleDraw(bool enableScientificNotation = false)
: m_scientificNotationEnabled(enableScientificNotation)
{
}
virtual QwtText label(double value) const override;
{
if (m_scientificNotationEnabled)
{
return QwtScaleDraw::label(value);
}
else
{
return QwtText(QString::number(value, 'f', 0));
}
}
private:
bool m_scientificNotationEnabled;
};
then to use it, you do something like:
QwtPlot myplot;
myplot->setAxisScaleDraw(xBottom, new QScaleDraw);
Result
来源:https://stackoverflow.com/questions/32761035/qwt-turn-off-scientific-notation-for-axis-labels