跪求正弦动态曲线demo参考
研究了一个星期,还是没有成功搞出来,请高手指点
[解决办法]
widget.h文件
#include <QtGui/QWidget>
class Widget : public QWidget
{
Q_OBJECT
public:
Widget(QWidget *parent = 0);
~Widget();
protected:
void paintEvent(QPaintEvent *event);
private:
int buffer[400];
};
widget.cpp文件
#include "Widget.h"
#include "math.h"
#include <QPainter>
#define PI 3.1415926
Widget::Widget(QWidget *parent)
: QWidget(parent)
{
setSizePolicy(QSizePolicy::Minimum,QSizePolicy::Minimum);
setBackgroundRole(QPalette::Dark);
resize(320, 240);
setWindowTitle(tr("Paint Demo"));
for( int i=0; i<400; i++ ) {
buffer[i] = (int)( sin( (i*PI) /100 ) * 70 );
}
}
void Widget::paintEvent(QPaintEvent *event)
{
QPainter painter(this);
QPoint beginPoint;
QPoint endPoint;
painter.setPen( Qt::blue );
for( int i=0; i<399; i++ ) {
beginPoint.setX( i );
beginPoint.setY( buffer[i]+100 );
endPoint.setX( i+1 );
endPoint.setY( buffer[i+1]+100 );
painter.drawLine( beginPoint, endPoint );
}
}