ページ

2014年1月2日木曜日

レイアウトを使って凡例をキャンバスの中に表示する。 :Qwt



よく分からないけど、とりあえずやってみた。
#include "mainwindow.h"
#include <QApplication>
#include <QDebug>
#include <qwt_plot.h>
#include <qwt_plot_curve.h>
#include <qwt_legend.h>
#include <qwt_plot_layout.h>
#include <QVBoxLayout>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QwtPlot *plot = new QwtPlot;
// サインカーブ
QwtPlotCurve *sinCurve = new QwtPlotCurve();
sinCurve->setTitle( "sin curve" );
sinCurve->setPen( Qt::blue, 2 ),sinCurve->setRenderHint( QwtPlotItem::RenderAntialiased, true );
QVector<double> sinX;//空のベクタ宣言
QVector<double> sinY;//空のベクタ宣言
for( double d = 0.0 ; d <= 2.0 ; d += 0.01 ){
sinX.append( d );
sinY.append( sin(2.0*M_PI*d) );
sinCurve->setSamples(sinX.data(), sinY.data(), sinX.count());
}
sinCurve->attach( plot );
// 凡例をキャンバスに表示
QwtLegend *legend = new QwtLegend(plot);//widget
plot->insertLegend( legend );//NULL
QVBoxLayout *layout = new QVBoxLayout;//レイアウトを設定
layout->addWidget(legend);
QWidget *myCanbas = plot->canvas();//グラフのキャンバス
myCanbas->setLayout(layout);
plot->insertLegend( NULL );//NULL
plot->resize( 600, 400 );
plot->show();
return a.exec();
}
view raw main.cpp hosted with ❤ by GitHub


0 件のコメント:

コメントを投稿