Hello to everyone,
I have written a piece of code to show the result of a frequency spectrum computation.
The curve is well plotted, but I am missing the legend. I tried out several variants, but nothing helped.
See the code below:

Qt Code:
  1. // plot object
  2. QwtPlot myPlot;
  3. myPlot.setTitle( "Autospektrum!" );
  4. myPlot.setAxisTitle( QwtPlot::xBottom, "frequency bin" );
  5. myPlot.setAxisTitle( QwtPlot::yLeft, "log Amplitude" );
  6. myPlot.setCanvasBackground( QColor( Qt::darkBlue ));
  7.  
  8. // grid
  9. grid.enableXMin(true);
  10. grid.setMajPen( QPen( Qt::white, 0, Qt::DotLine ));
  11. grid.setMinPen( QPen( Qt::gray, 0 , Qt::DotLine ));
  12. grid.attach( &myPlot );
  13.  
  14. // define the curve object
  15. curve.setSamples( pXData, pResults, FFT_LENGTH );
  16. curve.setPen( QPen( Qt::yellow ));
  17. curve.setRenderHint( QwtPlotItem::RenderAntialiased );
  18. curve.setLegendAttribute( QwtPlotCurve::LegendShowLine );
  19. curve.attach( &myPlot );
  20.  
  21. // legend
  22. QwtLegend legend;
  23. legend.setItemMode( QwtLegend::ReadOnlyItem );
  24.  
  25. QwtLegendItem legendItem;
  26. legendItem.setText( QwtText( "Autospektrum" ));
  27. myPlot.insertLegend( &legend, QwtPlot::RightLegend );
  28.  
  29. myPlot.replot();
  30. myPlot.show();
To copy to clipboard, switch view to plain text mode