Qwt turn off scientific notation for axis labels

做~自己de王妃 提交于 2019-12-24 12:47:24

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!