QCustomPlot.tar.gz をダウンロードして解凍する。
ダウンロードパージ:http://www.qcustomplot.com/index.php/download
Qt GUI アプリケーションでプロジェクトを作成する。
プロジェクトを選択して、右クリックから、既存ファイルの追加を選択して、
qcustomplot.h
qcustomplot.cpp
の2つのファイルをプロジェクトに追加する。
.pro ファイルに追記する。
QT += printsupport
デザインから Windowに Widgets を追加する。
追加した Widget を選択して、右クリックから、格上げ先を指定を選択する。
新しい格上げされたクラス名にQCustomPlot と入力して、追加ボタンをクリックする。
格上げされたクラスから、追加されたヘッダファイルを選択して、
格上げボタンを押す。
Widget のクラス名がQCustomPlot に変わる。
ウィンドウの大きさに Widget の大きさを合わせるためにレイアウトを指定する。
ソースコードを記入する。
QCustomPlot のサイトのTutorials の Basics Plotting のソースコード
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "mainwindow.h" | |
#include "ui_mainwindow.h" | |
MainWindow::MainWindow(QWidget *parent) : | |
QMainWindow(parent), | |
ui(new Ui::MainWindow) | |
{ | |
ui->setupUi(this); | |
QCustomPlot *customPlot = ui->widget; | |
// generate some data: | |
QVector<double> x(101), y(101); // initialize with entries 0..100 | |
for (int i=0; i<101; ++i) | |
{ | |
x[i] = i/50.0 - 1; // x goes from -1 to 1 | |
y[i] = x[i]*x[i]; // let's plot a quadratic function | |
} | |
// create graph and assign data to it: | |
customPlot->addGraph(); | |
customPlot->graph(0)->setData(x, y); | |
// give the axes some labels: | |
customPlot->xAxis->setLabel("x"); | |
customPlot->yAxis->setLabel("y"); | |
// set axes ranges, so we see all data: | |
customPlot->xAxis->setRange(-1, 1); | |
customPlot->yAxis->setRange(0, 1); | |
customPlot->replot(); | |
} | |
MainWindow::~MainWindow() | |
{ | |
delete ui; | |
} |
0 件のコメント:
コメントを投稿