1

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?

Nicolas Holthaus
  • 7,763
  • 4
  • 42
  • 97
  • 2
    Just take a look at this post http://stackoverflow.com/questions/18587571/change-axis-ticks-and-label-to-switch-between-millimeter-and-inch-in-qwt-plot You can override scale draw class like I did. – bkausbk Sep 24 '15 at 12:15
  • One additional comment for your special case, overriding `QwtScaleDraw::label(double)` in your own derived `QwtScaleDraw` class should be sufficient. – bkausbk Sep 24 '15 at 12:26
  • @bkausbk your answer actually helped me solve a couple problems, I wish I could have upvoted it once for each! – Nicolas Holthaus Oct 15 '15 at 15:02

1 Answers1

2

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

Nicolas Holthaus
  • 7,763
  • 4
  • 42
  • 97