huozhenhua的个人博客分享 http://blog.sciencenet.cn/u/huozhenhua

博文

QWT 的几个要用的例子之一 simpleplot

已有 6395 次阅读 2015-12-2 10:58 |个人分类:C/C++|系统分类:科研笔记

#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




https://blog.sciencenet.cn/blog-623402-940465.html

上一篇:qwt-ing,做出东西总得要应用,去coding吧
收藏 IP: 218.76.28.*| 热度|

0

该博文允许注册用户评论 请点击登录 评论 (1 个评论)

数据加载中...

Archiver|手机版|科学网 ( 京ICP备07017567号-12 )

GMT+8, 2024-7-17 19:31

Powered by ScienceNet.cn

Copyright © 2007- 中国科学报社

返回顶部