Wave diagram in QT.. There was some functionality issues in logic. I tried a wave diagram logically using QPainter. Wave diagram is drawn perfectly but there was one line has drawn.. Any one help me to solve this problem.
//dialog.cpp
#include "dialog.h"
#include "ui_dialog.h"
#include <QtMath>
#include <QDebug>
#include <QDialog>
#include <QTGui>
#include <QtCore>
Dialog::Dialog(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::Dialog)
{
    ui->setupUi(this);
}
Dialog::~Dialog()
{
    delete ui;
}
void Dialog::paintEvent(QPaintEvent *e)
{
    e->accept();
    float scale = 40;
    //boolean negativeX = true;
    float width = 500;
    float height = 108;
    QPainter painter(this);
    QPen linepen(Qt::red);
    linepen.setWidth(2);
    QPoint p1;
    QPoint p2;
    painter.setPen(linepen);
    float xx, yy, dx=4, x0=width / 2, y0=height / 2;
    //float iMax = (width - x0) / dx;
    float iMax = 63;
    //float iMin = negativeX ? -x0 / dx : 0;
    float iMin = -63;
    for (int i=iMin;i<=iMax;i++) {
           float x = x0+xx;
           float y = y0-yy;
         p1.setX(x);
         p1.setY(y);
         xx = dx*i;
         float xscl = xx/scale;
         yy = scale * qCos( 3* xscl );
           x = x0+xx;
           y = y0-yy;
         p2.setX(x);
         p2.setY(y);
         painter.drawLine(p1, p2);
     }
   }
// dialog.h
protected:
    void paintEvent(QPaintEvent *e);
// main.cpp
QApplication a(argc, argv);
Dialog w;
w.show();
Aucun commentaire:
Enregistrer un commentaire