Results 1 to 5 of 5

Thread: Qwt dynamic x axis labels

  1. #1
    Join Date
    Nov 2012
    Location
    Kentucky, USA
    Posts
    46
    Thanks
    21
    Qt products
    Qt4
    Platforms
    Windows

    Default Qwt dynamic x axis labels

    I am making a spectrum display based on the RtFFT code.
    My problem is how to set the x axis scale labels dynamically.
    Looked at the cpuplot example and they are set dynamically but in an incremental fashion.
    Mine need to be recalculated on the fly. The setAxisScale is done using an Xmin value and the set sample rate, so those are the axis labels that show up on the display. The center of the display will correspond to a radio frequency value that is known.
    I know how to calculate the correct label values, but how to apply them? QwtScaleDraw? But I don't see any function to set the label values.

    Thanks for any help.

  2. #2
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,311
    Thanked 879 Times in 827 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Qwt dynamic x axis labels

    Quote Originally Posted by K4ELO View Post
    I am making a spectrum display based on the RtFFT code.
    My problem is how to set the x axis scale labels dynamically.
    The labels are always for the major ticks. Is your question about how to set the positions of the major ticks - or how to modify the tick labels ?
    .
    Looked at the cpuplot example and they are set dynamically but in an incremental fashion..
    The cpuplot example sets the range of the axis scale dynamically - it doesn't deal with ticks at all. The tick labels display a date time string instead of a number..

    If all you want to do is to set the range and the positions of the ticks manually QwtPlot::setAxisScaleDiv() is what you are looking for.

    If true note that with Qwt 6.0 you can't use the default constructor of QwtScaleDiv, you have to use one of the other constructors ( as this issue is gone with Qwt 6.1 I don't go into detail ). Otherwise - please repeat your question somehow related to the terminology of my answer.

    Uwe

  3. #3
    Join Date
    Nov 2012
    Location
    Kentucky, USA
    Posts
    46
    Thanks
    21
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Qwt dynamic x axis labels

    Thanks Uwe. I just need to change the labels. For example, if the radio is tuned to a frequency of 7.190 mHz, then the x axis label in the center of the display should be 7.190 The x min would display 7.190 - sample rate/2 and the x max would display 7.190 + sample rate/2

    I tried the following code:
    Qt Code:
    1. class NewScaleDraw : public QwtScaleDraw
    2. {
    3. public:
    4. NewScaleDraw()
    5. {
    6. }
    7.  
    8. virtual QwtText label(double value) const
    9. {
    10. float freqLabel = (::centerFreq-(value/2000000));
    11. QString strFreqLabel = QString("%1").arg(freqLabel);
    12. return strFreqLabel;
    13. }
    14. };
    15.  
    16. void RtControl::newScale(QString freq)
    17. {
    18. d_.view->setAxisScaleDraw(QwtPlot::xTop, new NewScaleDraw());
    19. }
    To copy to clipboard, switch view to plain text mode 

    Where newScale is called each time the radio changes frequency, but the labels are not changing.
    Is this the correct approach?

  4. #4
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,311
    Thanked 879 Times in 827 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Qwt dynamic x axis labels

    You have to do a replot() - or at least do a QwtPlot::updateAxes() to make your changes happen.

    Creating and assigning a new NewScaleDraw object each time is o.k. - but it would be enough to use one object, where you invalidate its cache:

    Qt Code:
    1. class NewScaleDraw : public QwtScaleDraw
    2. {
    3. public:
    4. ...
    5. void reset()
    6. {
    7. invalidateCache();
    8. }
    9. };
    10.  
    11. void RtControl::newScale(QString freq)
    12. {
    13. dynamic_cast<NewScaleDraw>(d_view->axisScaleDraw())->reset();
    14. d_view->updateAxes();
    15. }
    To copy to clipboard, switch view to plain text mode 
    Uwe

  5. The following user says thank you to Uwe for this useful post:

    K4ELO (15th March 2013)

  6. #5
    Join Date
    Nov 2012
    Location
    Kentucky, USA
    Posts
    46
    Thanks
    21
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Qwt dynamic x axis labels

    Thanks Uwe - still not working but I'm not giving up. My NewScaleDraw gets executed on app startup but not when the frequency changes which is whats needed. So the axis labels are still fixed at the original values based on the sample rate.

    Correction: when this line of code executes
    d_.view->setAxisScaleDraw(QwtPlot::xTop, new NewScaleDraw);

    The NewScaleDraw class constructor is executed, but not the
    virtual QwtText label(double value) const
    Last edited by K4ELO; 15th March 2013 at 21:56.

Similar Threads

  1. QwtPlot axis labels
    By Kutuska in forum Qwt
    Replies: 7
    Last Post: 29th August 2012, 16:08
  2. How to hide axis labels
    By repepo in forum Qwt
    Replies: 5
    Last Post: 10th November 2011, 08:03
  3. Labels on axis.
    By eugene in forum Qwt
    Replies: 5
    Last Post: 6th August 2010, 13:30
  4. Axis with more labels
    By rakkar in forum Qwt
    Replies: 1
    Last Post: 11th October 2009, 09:26
  5. Relocating axis labels
    By malcom2073 in forum Qwt
    Replies: 0
    Last Post: 9th May 2008, 13:01

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.