qwtTest002.pro
#------------------------------------------------- # # Project created by QtCreator 2013-11-29T11:23:42 # #------------------------------------------------- QT += core gui CONFIG += qwt greaterThan(QT_MAJOR_VERSION, 4): QT += widgets TARGET = qwtTest002 TEMPLATE = app SOURCES += main.cpp\ plot.cpp HEADERS += plot.h FORMS += plot.ui
plot.h
#ifndef PLOT_H #define PLOT_H #include <QMainWindow> #include <qwt_plot.h> namespace Ui { class Plot; } class Plot : public QwtPlot { Q_OBJECT public: explicit Plot(QWidget *parent = 0); ~Plot(); private: Ui::Plot *ui; }; #endif // PLOT_Hmain.cpp
#include "plot.h" #include <QApplication> int main(int argc, char *argv[]) { QApplication a(argc, argv); Plot w; w.show(); return a.exec(); }
plot.cpp
#include "plot.h" #include "ui_plot.h" Plot::Plot(QWidget *parent) : QwtPlot(parent) { setTitle( "Plot Demo" );//グラフのタイトル } Plot::~Plot() { //ウインドウ終了 }
examples フォルダにある。simpleplot を参考に書いてみる。
plot.cpp
#include "plot.h" #include "ui_plot.h" #include <qwt_plot.h> #include <qwt_plot_curve.h> #include <qwt_plot_grid.h> #include <qwt_symbol.h> #include <qwt_legend.h> Plot::Plot(QWidget *parent) : QwtPlot(parent) { setTitle( "Plot Demo" );//グラフのタイトル setCanvasBackground( Qt::white ); setAxisScale( QwtPlot::yLeft, 0.0, 10.0 ); insertLegend( new QwtLegend() ); QwtPlotGrid *grid = new QwtPlotGrid(); grid->attach( this ); QwtPlotCurve *curve = new QwtPlotCurve(); curve->setTitle( "Some Points" ); curve->setPen( Qt::blue, 4 ), curve->setRenderHint( QwtPlotItem::RenderAntialiased, true ); QwtSymbol *symbol = new QwtSymbol( QwtSymbol::Ellipse, QBrush( Qt::yellow ), QPen( Qt::red, 2 ), QSize( 8, 8 ) ); curve->setSymbol( symbol ); QPolygonF points; points << QPointF( 0.0, 4.4 ) << QPointF( 1.0, 3.0 ) << QPointF( 2.0, 4.5 ) << QPointF( 3.0, 6.8 ) << QPointF( 4.0, 7.9 ) << QPointF( 5.0, 7.1 ); curve->setSamples( points ); curve->attach( this ); resize( 600, 400 ); } Plot::~Plot() { //ウインドウ終了 }