Qwt关闭轴标签的科学记数法 [英] Qwt turn off scientific notation for axis labels

查看:318
本文介绍了Qwt关闭轴标签的科学记数法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

默认情况下, Qwt 以科学计数法在轴上显示大数字:





对于我的应用程序,我真的想关闭或重新格式化标签。通过


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?

解决方案

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

这篇关于Qwt关闭轴标签的科学记数法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆