Created
January 1, 2014 20:03
-
-
Save yamato8/8211025 to your computer and use it in GitHub Desktop.
レイアウトを使って凡例をキャンバスの中に表示する。:Qwt
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 <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(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment