PDA

View Full Version : How to use qwt?



ssaguiar
29th April 2011, 03:03
Hi:

I wish to know how can I use the qwt in my app because I just don't get it. My app is working ok, but I need to plot a 2D grph in a QLabel container (or anything that is more apropriate to use with qwt).
I tried but can't find where to insert the code. The qwt is very poor in tutorials.
I wish to have in my app something like the QwtSpectrogram example.
Attached is my code.

Thanks for any help.

ssaguiar
30th April 2011, 22:51
I have found how to make the 2D graphics.
At the end of my mainwindow.cpp, i have this code:


void MainWindow::View_tank_Details(QString local)
{
QwtPlot *myPlot = new QwtPlot;
QwtPlotCurve *m_curve = new QwtPlotCurve;

for (refIndx=0; refIndx<16; refIndx++)
{
if (cardinalP[refIndx].contains(local))
{
//ui->Tanque1Level->display((fuelvalues[refIndx]*FUELTANKCAP)/1023);
TankIndex = refIndx;
ui->Tanque1Level->display(rand() % 30000);
ui->GraphTitle->setText(local);
}
}

myPlot = new QwtPlot(ui->GraphPlot );
myPlot->setGeometry( 5, 70, 590, 325 );
myPlot->setStyleSheet("background-color:black; color:rgb(255,255,255);border: 0px;");
//myPlot->setTitle(title);
myPlot->setAxisTitle(QwtPlot::xBottom, "Horas");
myPlot->setAxisTitle(QwtPlot::yLeft, "Litros");
myPlot->setAxisScale(QwtPlot::xBottom, 0, 96);//48);
myPlot->setAxisMaxMajor(QwtPlot::xBottom, 12);//24);
myPlot->setAxisMaxMinor(QwtPlot::xBottom, 0);
myPlot->setAxisScale(QwtPlot::yLeft, 0, 30000);

// grid
QwtPlotGrid *grid = new QwtPlotGrid;
grid->enableXMin(true);
grid->setMajPen(QPen(Qt::white, 0, Qt::DotLine));
grid->setMinPen(QPen(Qt::white, 0 , Qt::DotLine));
grid->attach(myPlot);

for (int i = 0; i < 97; i++)//49; i++)
{
xplot[i] = i;
//yplot[i] = (rand() % 30000);//i * (rand() % 30000) * cos(i / M_PI);
yplot[i] = (i * (rand() % 300) * cos(i / M_PI));
//yplot[i] = testcnt;
}

m_curve= new QwtPlotCurve();
m_curve->setSymbol(new QwtSymbol(QwtSymbol::Cross, Qt::NoBrush, QPen(Qt::white), QSize(5, 5) ) );
//m_curve->setPen(QColor(Qt::yellow));
m_curve->setCurveAttribute(QwtPlotCurve::Fitted);
m_curve->setLegendAttribute(QwtPlotCurve::LegendShowLine);
m_curve->setPen(QPen(QColor::fromRgb(0, 0, 255), 1));
m_curve->setRawSamples(xplot, yplot, 97);//49);
m_curve->setTitle("Curva do nivel de combustivel");
m_curve->attach(myPlot);

QwtPlotPicker *d_picker = new QwtPlotPicker(QwtPlot::xBottom, QwtPlot::yLeft,
QwtPlotPicker::CrossRubberBand, QwtPicker::AlwaysOn,
myPlot->canvas());

d_picker->setRubberBandPen(QColor(Qt::green));
d_picker->setRubberBand(QwtPicker::CrossRubberBand);
d_picker->setTrackerPen(QColor(Qt::yellow));


myPlot->show();
}


It created the plot area, adds the grid, plot the curve and adds the QwtPlotPicker.

Now, i just need to:

1 - make the QwtPlotPicker show just the data of the marked points (the ones that were ploted from the tables), not all the points of the plot;
2 - make the QwtPlotPicker text without the decimal values (just the left values);
3 - make the QwtPlotPicker show only the values of the Y (liters) and not the X (hours);
4 - make the QwtPlotPicker semi-transparent (now the background is transparent);

Sergio