P@u1
5th July 2011, 16:29
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:
class QwtTest : public QMainWindow
{
Q_OBJECT
public:
QwtTest(QWidget *parent = 0, Qt::WFlags flags = 0);
~QwtTest();
protected:
void timerEvent(QTimerEvent * event);
private:
Ui::QwtTestClass ui;
double * xData_;
double * yData_;
int dataSize_;
int currXPos_;
int sinPos_;
int scaleFac;
QwtPlotCurve curve_;
static const double pi;
};
const double QwtTest::pi = 3.14159265358979323846264338327950;
QwtTest::QwtTest(QWidget *parent, Qt::WFlags flags)
: QMainWindow(parent, flags),
currXPos_(0),
sinPos_(0),
scaleFac(1)
{
ui.setupUi(this);
ui.qwtPlot->setAxisAutoScale(QwtPlot::yLeft);
dataSize_ = 200;
xData_ = new double[dataSize_];
yData_ = new double[dataSize_];
for(int i = 0; i < dataSize_; ++i)
{
xData_[i] = double(i);
yData_[i] = sin(2*pi*i/dataSize_);
}
curve_.setRawSamples(xData_, yData_, dataSize_);
curve_.attach(ui.qwtPlot);
ui.qwtPlot->replot();
QObject::startTimer(1000/60);
}
QwtTest::~QwtTest()
{
delete[] xData_;
delete[] yData_;
}
void QwtTest::timerEvent(QTimerEvent * event)
{
for(int i = 0; i < 5; ++i)
{
yData_[currXPos_] = scaleFac*sin(2*pi*sinPos_/(0.169*dataSize_));
++sinPos_;
currXPos_ = (currXPos_ + 1) % dataSize_;
}
++scaleFac;
//ui.qwtPlot->setAxisScale(QwtPlot::yLeft, -1000, 1000);
ui.qwtPlot->replot();
}
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!
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:
class QwtTest : public QMainWindow
{
Q_OBJECT
public:
QwtTest(QWidget *parent = 0, Qt::WFlags flags = 0);
~QwtTest();
protected:
void timerEvent(QTimerEvent * event);
private:
Ui::QwtTestClass ui;
double * xData_;
double * yData_;
int dataSize_;
int currXPos_;
int sinPos_;
int scaleFac;
QwtPlotCurve curve_;
static const double pi;
};
const double QwtTest::pi = 3.14159265358979323846264338327950;
QwtTest::QwtTest(QWidget *parent, Qt::WFlags flags)
: QMainWindow(parent, flags),
currXPos_(0),
sinPos_(0),
scaleFac(1)
{
ui.setupUi(this);
ui.qwtPlot->setAxisAutoScale(QwtPlot::yLeft);
dataSize_ = 200;
xData_ = new double[dataSize_];
yData_ = new double[dataSize_];
for(int i = 0; i < dataSize_; ++i)
{
xData_[i] = double(i);
yData_[i] = sin(2*pi*i/dataSize_);
}
curve_.setRawSamples(xData_, yData_, dataSize_);
curve_.attach(ui.qwtPlot);
ui.qwtPlot->replot();
QObject::startTimer(1000/60);
}
QwtTest::~QwtTest()
{
delete[] xData_;
delete[] yData_;
}
void QwtTest::timerEvent(QTimerEvent * event)
{
for(int i = 0; i < 5; ++i)
{
yData_[currXPos_] = scaleFac*sin(2*pi*sinPos_/(0.169*dataSize_));
++sinPos_;
currXPos_ = (currXPos_ + 1) % dataSize_;
}
++scaleFac;
//ui.qwtPlot->setAxisScale(QwtPlot::yLeft, -1000, 1000);
ui.qwtPlot->replot();
}
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!