||
#include <qapplication.h>
#include <qwt_plot.h>
#include <qwt_plot_curve.h>
#include <qwt_plot_grid.h>
#include <qwt_symbol.h>
#include <qwt_legend.h>
int main( int argc, char **argv )
{
QApplication a( argc, argv ); //初使化QT
QwtPlot plot; //声名对象,我要用你画图了啊,告诉你一声
plot.setTitle( "Plot Demo" );// title
plot.setCanvasBackground( Qt::white );//背景颜色,Canvas感觉好高大上
plot.setAxisScale( QwtPlot::yLeft, 0.0, 10.0 );//AxisScale
plot.insertLegend( new QwtLegend() );//Legend
QwtPlotGrid *grid = new QwtPlotGrid();//声名grid
grid->attach( &plot );//把grid绑到plot上,不是声名了就有用,得绑上
QwtPlotCurve *curve = new QwtPlotCurve();//声名 Curve
curve->setTitle( "Some Points" );
curve->setPen( Qt::blue, 4 ), //画笔颜色和粗细
curve->setRenderHint( QwtPlotItem::RenderAntialiased, true ); //Render
QwtSymbol *symbol = new QwtSymbol( QwtSymbol::Ellipse,
QBrush( Qt::yellow ), QPen( Qt::red, 2 ), QSize( 8, 8 ) ); //Symbol
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( &plot );
看
plot.resize( 600, 400 );
plot.show();
搞定
return a.exec();//结束
}
simpleplot.pro要进行一点小修改,这个程序才能独立编译
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
LIBS += -lqwt
INCLUDEPATH += -I "/usr/local/qwt-6.1.2/include"
TARGET = simpleplot
SOURCES =
simpleplot.cpp
Archiver|手机版|科学网 ( 京ICP备07017567号-12 )
GMT+8, 2024-12-23 20:52
Powered by ScienceNet.cn
Copyright © 2007- 中国科学报社