I implemented an example based on the 'spectrogram' example by exchanging the 'SpectrogramData' class with the build in 'QwtMatrixRasterData' class.
The problem is that the data is not shown and the plot remains empty. I would like to know what is missing in this code.

Qt Code:
  1. #include <qwt_plot.h>
  2.  
  3. #include <qwt_plot_spectrogram.h>
  4. #include <qwt_matrix_raster_data.h>
  5.  
  6.  
  7. class QMatrixPlot : public QwtPlot
  8. {
  9. Q_OBJECT
  10. public:
  11. QMatrixPlot(QWidget *parent = NULL);
  12. virtual ~QMatrixPlot()
  13. {
  14. if (d_spectrogram)
  15. delete d_spectrogram;
  16. }
  17.  
  18. void setMatrixData(const QVector< double > &values, int numColumns);
  19.  
  20. private:
  21. QwtPlotSpectrogram * d_spectrogram;
  22. QwtMatrixRasterData * m_MatrixRasterData;
  23.  
  24. int d_alpha;
  25. int d_mapType;
  26.  
  27. };
To copy to clipboard, switch view to plain text mode 

Qt Code:
  1. #include "QMatrixPlot.h"
  2. #include "qcolormap.h"
  3. #include "qwt_plot_layout.h"
  4. #include "qwt_scale_widget.h"
  5.  
  6. QMatrixPlot::QMatrixPlot(QWidget *parent ):
  7. QwtPlot( parent ),
  8. d_alpha(255)
  9. {
  10.  
  11. d_spectrogram = new QwtPlotSpectrogram();
  12. d_spectrogram->setRenderThreadCount( 0 ); // use system specific thread count
  13. d_spectrogram->setCachePolicy( QwtPlotRasterItem::PaintCache );
  14.  
  15. m_MatrixRasterData = new QwtMatrixRasterData();
  16. d_spectrogram->setData( m_MatrixRasterData );
  17. d_spectrogram->attach( this );
  18.  
  19. }
  20.  
  21. void QMatrixPlot::setMatrixData(const QVector< double > &values, int numColumns)
  22. {
  23. m_MatrixRasterData->setValueMatrix (values, numColumns);
  24.  
  25. const QwtInterval zInterval = d_spectrogram->data()->interval( Qt::ZAxis );
  26. setAxisScale( QwtPlot::yRight, zInterval.minValue(), zInterval.maxValue() );
  27.  
  28. QwtScaleWidget *axis = axisWidget( QwtPlot::yRight );
  29. axis->setColorMap( zInterval, QColorMap::map(d_mapType) );
  30. }
To copy to clipboard, switch view to plain text mode 

Qt Code:
  1. #include <QtWidgets/QApplication>
  2. #include <QtWidgets/QMainWindow>
  3.  
  4. #include "qmatrixplot.h"
  5.  
  6. #include <vector>
  7. using std::vector;
  8.  
  9. int main( int argc, char **argv )
  10. {
  11. QApplication a( argc, argv );
  12.  
  13. QMatrixPlot * plot = new QMatrixPlot();
  14. plot->setTitle( "2D Plot Demo" );
  15.  
  16. // create data
  17. QVector<double> x(100);
  18. QVector<double> y1(x.size());
  19.  
  20. for (size_t i = 0; i< x.size(); ++i) { x[i] = int(i)-50; }
  21. for (size_t i = 0; i< y1.size(); ++i) { y1[i] = sin(double(x[i])/10.0); }
  22.  
  23. plot->setMatrixData(y1, 10);
  24. plot->replot();
  25.  
  26. QMainWindow window;
  27. window.setCentralWidget(plot);
  28. window.resize(800, 600);
  29. window.show();
  30.  
  31. return a.exec();
  32. }
To copy to clipboard, switch view to plain text mode