Qwt turn off scientific notation for axis labels

2019-08-31 12:28发布

By default, Qwt displays large numbers on the axis in scientific notation:

axis labels 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条回答
我欲成王,谁敢阻挡
2楼-- · 2019-08-31 12:52

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

axis labels without scientific notation

查看更多
登录 后发表回答