Results 1 to 2 of 2

Thread: Is it possible to set precision of axis tick labels?

  1. #1
    Join Date
    Oct 2009
    Posts
    33
    Thanks
    2

    Default Is it possible to set precision of axis tick labels?

    Hey,

    Is it possible to set precision (ie. number of digits used for floating point representation) for the axis tick labels? For example, can I display the value '25' as '25.0' instead?


    Regards,

    kif

  2. #2
    Join Date
    Oct 2009
    Posts
    28
    Thanks
    4
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Is it possible to set precision of axis tick labels?

    hello.

    Yes It is possible. I did it by subclassing QwtScaleDraw and reimplementing the method QwtText label(double value).

    Qt Code:
    1. class CExpScaleDraw : public QwtScaleDraw
    2. {
    3. public:
    4. CExpScaleDraw();
    5. virtual ~CExpScaleDraw();
    6.  
    7. void ajustar();
    8.  
    9. protected:
    10. virtual QwtText label(double value) const;
    11.  
    12. private:
    13. int numDec;
    14. };
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. QwtText CExpScaleDraw::label(double value) const
    2. {
    3. QString aux = QString::number(value,'f',4);
    4.  
    5. bool salir = false;
    6. int i = aux.count()-1;
    7. while(i>=0 && !salir)
    8. {
    9. if(aux.at(i) == '0')
    10. {
    11. aux.remove(i,1);
    12. i--;
    13. }
    14.  
    15. else
    16. salir = true;
    17. }
    18. if(aux.at(i) == '.')
    19. aux.remove(i,1);
    20. return aux;
    21. }
    To copy to clipboard, switch view to plain text mode 


    And when you create the plot, just insert this:

    Qt Code:
    1. CExpScaleDraw *expSD = new CExpScaleDraw();
    2. qwtPlot->setAxisScaleDraw(QwtPlot::yLeft,expSD);
    To copy to clipboard, switch view to plain text mode 

    I hope that helps.
    Regards.

Similar Threads

  1. Replies: 4
    Last Post: 10th June 2010, 14:31
  2. Axis Tick Labels Overlap
    By amoswood in forum Qwt
    Replies: 3
    Last Post: 8th June 2010, 16:52
  3. y-axis tick labels trimmed
    By gib in forum Qwt
    Replies: 2
    Last Post: 2nd April 2010, 06:19
  4. Tick Labels for Slider
    By jcraig in forum Qt Tools
    Replies: 2
    Last Post: 9th August 2007, 18:21
  5. QSlider with a custom set of labels for the tick marks?
    By whitefurrows in forum Qt Programming
    Replies: 3
    Last Post: 5th August 2007, 17:05

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.