Results 1 to 5 of 5

Thread: AxisAutoScale is not working

  1. #1
    Join Date
    Jun 2011
    Posts
    38
    Thanks
    8
    Thanked 1 Time in 1 Post

    Default AxisAutoScale is not working

    Hi,

    I wrote a very simple example to test qwt and recognized that the axisautoscale feature does not work for me so far...
    Here is the code:
    Qt Code:
    1. class QwtTest : public QMainWindow
    2. {
    3. Q_OBJECT
    4.  
    5. public:
    6. QwtTest(QWidget *parent = 0, Qt::WFlags flags = 0);
    7. ~QwtTest();
    8.  
    9. protected:
    10. void timerEvent(QTimerEvent * event);
    11.  
    12. private:
    13. Ui::QwtTestClass ui;
    14. double * xData_;
    15. double * yData_;
    16. int dataSize_;
    17. int currXPos_;
    18. int sinPos_;
    19. int scaleFac;
    20. QwtPlotCurve curve_;
    21. static const double pi;
    22. };
    23. const double QwtTest::pi = 3.14159265358979323846264338327950;
    24.  
    25. QwtTest::QwtTest(QWidget *parent, Qt::WFlags flags)
    26. : QMainWindow(parent, flags),
    27. currXPos_(0),
    28. sinPos_(0),
    29. scaleFac(1)
    30. {
    31. ui.setupUi(this);
    32. ui.qwtPlot->setAxisAutoScale(QwtPlot::yLeft);
    33. dataSize_ = 200;
    34.  
    35. xData_ = new double[dataSize_];
    36. yData_ = new double[dataSize_];
    37. for(int i = 0; i < dataSize_; ++i)
    38. {
    39. xData_[i] = double(i);
    40. yData_[i] = sin(2*pi*i/dataSize_);
    41. }
    42. curve_.setRawSamples(xData_, yData_, dataSize_);
    43. curve_.attach(ui.qwtPlot);
    44. ui.qwtPlot->replot();
    45. QObject::startTimer(1000/60);
    46. }
    47.  
    48. QwtTest::~QwtTest()
    49. {
    50. delete[] xData_;
    51. delete[] yData_;
    52. }
    53.  
    54. void QwtTest::timerEvent(QTimerEvent * event)
    55. {
    56. for(int i = 0; i < 5; ++i)
    57. {
    58. yData_[currXPos_] = scaleFac*sin(2*pi*sinPos_/(0.169*dataSize_));
    59. ++sinPos_;
    60. currXPos_ = (currXPos_ + 1) % dataSize_;
    61. }
    62. ++scaleFac;
    63. //ui.qwtPlot->setAxisScale(QwtPlot::yLeft, -1000, 1000);
    64. ui.qwtPlot->replot();
    65. }
    To copy to clipboard, switch view to plain text mode 

    I draws a sinus, which is getting bigger and bigger, but unfortunately the autoscale is not working, so after short time most parts of the sinus leave the visible area...
    Is the problem maybe, that autoscale does not work together with rawSamples?

    When I uncomment the line
    //ui.qwtPlot->setAxisScale(QwtPlot::yLeft, -1000, 1000);
    I can see how the scale changes, but that should be done automaticully...

    Thanks for help in advance!

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

    Default Re: AxisAutoScale is not working

    Quote Originally Posted by P@u1 View Post
    When I uncomment the line
    //ui.qwtPlot->setAxisScale(QwtPlot::yLeft, -1000, 1000);
    I can see how the scale changes ...
    Sure, setting an scale range explicitly disables autoscaling - you can't have both.

    Simply read the docs,
    Uwe

  3. #3
    Join Date
    Jun 2011
    Posts
    38
    Thanks
    8
    Thanked 1 Time in 1 Post

    Default Re: AxisAutoScale is not working

    I only added the line after I recognized that autoscale did not work to test if it works if i do it manually.
    With "uncomment" i meant removing the "//"
    With the line commented out it does no autoscale for me.

    My suggestion that autoscale just doesent work with setRawSamples was wrong?

    Please help :-)
    Last edited by P@u1; 5th July 2011 at 18:34.

  4. #4
    Join Date
    Jun 2011
    Posts
    38
    Thanks
    8
    Thanked 1 Time in 1 Post

    Default Re: AxisAutoScale is not working

    I added the line
    Qt Code:
    1. curve_.setRawSamples(xData_, yData_, dataSize_);
    To copy to clipboard, switch view to plain text mode 
    in the timerEvent and now its working.
    I didn't know that I need to set the samples again each time I apply changes to the data...

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

    Default Re: AxisAutoScale is not working

    Autoscaling uses the coordinates of the bounding rectangle. The bounding rectangle of the data is internally cached and when you update the samples behind the back of the data object the cached bounding rectangle gets wrong.

    Uwe

Similar Threads

  1. MVC example not working
    By yyiu002 in forum Newbie
    Replies: 1
    Last Post: 30th June 2010, 00:07
  2. My first app not working
    By Noks in forum Newbie
    Replies: 6
    Last Post: 2nd February 2010, 16:34
  3. Working with QThread
    By Fastman in forum Qt Programming
    Replies: 1
    Last Post: 27th February 2009, 22:35
  4. gtk not working in qt filesystem
    By apulu in forum Newbie
    Replies: 11
    Last Post: 18th April 2008, 10:22
  5. Mac OS X UI not working
    By hvengel in forum Qt Programming
    Replies: 3
    Last Post: 1st April 2006, 01:02

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.