PDA

View Full Version : QT 4.5 and Plotting data



Lezer
5th September 2012, 15:20
Hello,

I am newbie using QT, I need to made some plots and histogram. Searching in the web I see QWT and QCustomPlot. I would not use QWT because you need to add a new library into device, and QCustomPlot it isn't for QT 4.5.

is there another libraty like QCustomPlot?

Thank you

Uwe
5th September 2012, 19:07
You are asking for a library, but don't want to use Qwt because it is a library ?

Uwe

Lezer
6th September 2012, 07:38
More or less yes. I want something like QCustomPlot, but QT 4.5 compatible code.

Uwe
6th September 2012, 13:11
You can always copy the code of an open source library into your source tree ( taking care of the license !) instead of using it as library - there is nothing special about QCustomPlot beside that it propagates this way. So this is no criteria for a package ( the other way it is: when you need a library and there is none ).

I'm afraid you won't find something else than Qwt for Qt 4.5, but you can easily strip it down to a smaller size ( and copy the files to your project even if IMHO this doesn't makes much sense ). In qwt/src/src.pro you can see the list of files that are needed for the plot classes only - when building the library you can configure to build them only in qwtconfig.pri ). Additionally you can remove more files for the plot items you don't need ( f.e for curves only ).

As author of the Qwt package I don't want to compare packages, but I don't agree that things are much easier than this code:


#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::white );
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( QPen( 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( &plot );

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

return a.exec();
}

Uwe