qwt的使用實例

在.pro文件中加入canvas

INCLUDEPATH += /usr/include/qwt

LIBS += -L"/usr/lib/" -lqwt

 

頭文件:app

1 #include <qapplication.h>
2 #include <qwt_plot.h>
3 #include <qwt_plot_curve.h>
4 #include <qwt_plot_grid.h>
5 #include <qwt_symbol.h>
6 #include <qwt_legend.h>

 1 int main( int argc, char **argv ) 2 { 3 QApplication a( argc, argv ); ide

1     QwtPlot plot;
2     plot.setTitle( "Plot Demo" );
3     plot.setCanvasBackground( Qt::white );
4     plot.setAxisScale( QwtPlot::yLeft, 0.0, 10.0 );
5     plot.insertLegend( new QwtLegend() );

新建一個QwtPlot構件,即基本的繪圖表格spa

設置標題 "Plot Demo"3d

設置背景 白色   //canvas帆布code

void QwtPlot::setAxisScale ( int axisId, double min, double max, double stepSize = 0 )
Disable autoscaling and specify a fixed scale for a selected axis.
In updateAxes() the scale engine calculates a scale division from the specified parameters, that will be assigned to the scale widget. So updates of the scale widget usually happen delayed with the next replot.
Parameters
axisId      min           max           stepSize blog

Axis index       Minimum of the scale   Maximum of the scale  Major step size.ip

If step == 0 , the step size is calculated automatically using the maxMajor
setting.ci

對座標尺寸的初始化,設置左邊y 軸座標的範圍爲0~10,座標爲非自適應.不會自動變化get

設置新的一個圖例 //legend圖例

1     QwtPlotGrid *grid = new QwtPlotGrid();
2     grid->attach( &plot );
View Code

在錶盤中插入網格

 

1     QwtPlotCurve *curve = new QwtPlotCurve();
2     curve->setTitle( "Some Points" );
3     curve->setPen( Qt::blue, 4 ),
4     curve->setRenderHint( QwtPlotItem::RenderAntialiased, true );

新建一個曲線

設置標題爲"Some Points"

設置畫筆爲藍色,寬度4

設置曲線抗鋸齒

1     QwtSymbol *symbol = new QwtSymbol( QwtSymbol::Ellipse,
2         QBrush( Qt::yellow ), QPen( Qt::red, 2 ), QSize( 8, 8 ) );
3     curve->setSymbol( symbol );

設置符號格式,主要用來標記點

1     QPolygonF points;
2     points << QPointF( 0.0, 4.4 ) << QPointF( 1.0, 3.0 )
3         << QPointF( 2.0, 4.5 ) << QPointF( 3.0, 6.8 )
4         << QPointF( 4.0, 7.9 ) << QPointF( 5.0, 7.1 );
5     curve->setSamples( points );

新建一個QPolygonF類(Qt中自帶點集f->float)

其中

void QwtPlotCurve::setSamples ( QwtSeriesData < QPointF > ∗ data )
Assign a series of points
setSamples() is just a wrapper for setData() without any additional value - beside that it is easier to find for the
developer.

1     curve->attach( &plot );
2 
3     plot.resize( 600, 400 );
4     plot.show();
5 
6     return a.exec();
7 }

生成並畫圖


下面是源碼方便你們複製

#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 );

    QwtPlot plot;
    plot.setTitle( "Plot Demo" );
    plot.setCanvasBackground( Qt::green );
    plot.setAxisScale( QwtPlot::yLeft, 0.0, 10.0 );
    plot.insertLegend( new QwtLegend() );

    QwtPlotGrid *grid = new QwtPlotGrid();
    grid->attach( &plot );

    QwtPlotCurve *curve = new QwtPlotCurve();
    curve->setTitle( "Some Points" );
    curve->setPen( Qt::blue, 4 ),
    curve->setRenderHint( QwtPlotItem::RenderAntialiased, true );

    QwtSymbol *symbol = new QwtSymbol( QwtSymbol::Diamond,
        QBrush( Qt::black ), 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( &plot );

    plot.resize( 600, 400 );
    plot.show();

    return a.exec();
}
View Code
相關文章
相關標籤/搜索