Results 1 to 2 of 2

Thread: How to use qwt?

  1. #1
    Join Date
    Apr 2011
    Posts
    9
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default How to use qwt?

    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.
    Attached Files Attached Files
    Last edited by ssaguiar; 29th April 2011 at 03:09.

  2. #2
    Join Date
    Apr 2011
    Posts
    9
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: How to use qwt?

    I have found how to make the 2D graphics.
    At the end of my mainwindow.cpp, i have this code:
    Qt Code:
    1. void MainWindow::View_tank_Details(QString local)
    2. {
    3. QwtPlot *myPlot = new QwtPlot;
    4. QwtPlotCurve *m_curve = new QwtPlotCurve;
    5.  
    6. for (refIndx=0; refIndx<16; refIndx++)
    7. {
    8. if (cardinalP[refIndx].contains(local))
    9. {
    10. //ui->Tanque1Level->display((fuelvalues[refIndx]*FUELTANKCAP)/1023);
    11. TankIndex = refIndx;
    12. ui->Tanque1Level->display(rand() % 30000);
    13. ui->GraphTitle->setText(local);
    14. }
    15. }
    16.  
    17. myPlot = new QwtPlot(ui->GraphPlot );
    18. myPlot->setGeometry( 5, 70, 590, 325 );
    19. myPlot->setStyleSheet("background-color:black; color:rgb(255,255,255);border: 0px;");
    20. //myPlot->setTitle(title);
    21. myPlot->setAxisTitle(QwtPlot::xBottom, "Horas");
    22. myPlot->setAxisTitle(QwtPlot::yLeft, "Litros");
    23. myPlot->setAxisScale(QwtPlot::xBottom, 0, 96);//48);
    24. myPlot->setAxisMaxMajor(QwtPlot::xBottom, 12);//24);
    25. myPlot->setAxisMaxMinor(QwtPlot::xBottom, 0);
    26. myPlot->setAxisScale(QwtPlot::yLeft, 0, 30000);
    27.  
    28. // grid
    29. QwtPlotGrid *grid = new QwtPlotGrid;
    30. grid->enableXMin(true);
    31. grid->setMajPen(QPen(Qt::white, 0, Qt::DotLine));
    32. grid->setMinPen(QPen(Qt::white, 0 , Qt::DotLine));
    33. grid->attach(myPlot);
    34.  
    35. for (int i = 0; i < 97; i++)//49; i++)
    36. {
    37. xplot[i] = i;
    38. //yplot[i] = (rand() % 30000);//i * (rand() % 30000) * cos(i / M_PI);
    39. yplot[i] = (i * (rand() % 300) * cos(i / M_PI));
    40. //yplot[i] = testcnt;
    41. }
    42.  
    43. m_curve= new QwtPlotCurve();
    44. m_curve->setSymbol(new QwtSymbol(QwtSymbol::Cross, Qt::NoBrush, QPen(Qt::white), QSize(5, 5) ) );
    45. //m_curve->setPen(QColor(Qt::yellow));
    46. m_curve->setCurveAttribute(QwtPlotCurve::Fitted);
    47. m_curve->setLegendAttribute(QwtPlotCurve::LegendShowLine);
    48. m_curve->setPen(QPen(QColor::fromRgb(0, 0, 255), 1));
    49. m_curve->setRawSamples(xplot, yplot, 97);//49);
    50. m_curve->setTitle("Curva do nivel de combustivel");
    51. m_curve->attach(myPlot);
    52.  
    53. QwtPlotPicker *d_picker = new QwtPlotPicker(QwtPlot::xBottom, QwtPlot::yLeft,
    54. QwtPlotPicker::CrossRubberBand, QwtPicker::AlwaysOn,
    55. myPlot->canvas());
    56.  
    57. d_picker->setRubberBandPen(QColor(Qt::green));
    58. d_picker->setRubberBand(QwtPicker::CrossRubberBand);
    59. d_picker->setTrackerPen(QColor(Qt::yellow));
    60.  
    61.  
    62. myPlot->show();
    63. }
    To copy to clipboard, switch view to plain text mode 

    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

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.