PDA

View Full Version : Need help formatting plot axis



Jayl
28th March 2013, 15:32
Hey all, I'm relatively new to Qt/Qwt and have a little experience with C++. I've written a program that has a spectrogram plot in it. I got the spectrogram to display my data properly, but the y-axis is in units of Hertz and I want to display it in Khz. I know I need to reimplement the QwtScaleDraw class but I am at a loss as to how it is done, can anybody explain the process to me? Thanks in advance.

phenoboy
8th April 2013, 12:15
Check this example !

http://www.qtcentre.org/threads/10170-Qwt-and-custom-axis

put a debug line on 'label' method and you'll see what is going on.

Jayl
8th April 2013, 18:20
I got it to work, thanks for pointing me in the right direction! For anyone who's curious here's the code for the class declaration:

class hertz : public QwtScaleDraw
{
public:
hertz(){}
virtual QwtText label(double v) const;
};

I nested the hertz() class within another class (spectrogram), here's the code for the implementation:

QwtText spectrogram::hertz::label(double v) const{
if(v >= 1000 || v <= -1000)
return QString::number(v/1000.0);
else
return QString::number(v);
}