Results 1 to 3 of 3

Thread: Odd plotting behaviour

  1. #1
    Join Date
    May 2009
    Posts
    9
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Odd plotting behaviour

    I'm experiencing really odd behaviour with a Qwt plot. I'm plotting several datasets as QwtPlotCurves onto a QwtPlot, one dataset at a time, when a user clicks a button on the main app window.

    First call to plotting object (creates QwtPlot) - first plot appears fine.
    Second call to plotting object - no change; second plot doesn't appear.
    Third call - both second and third plots now appear.
    Fourth call - no change.
    Fifth call - fourth and fifth plots appear.
    etc

    Below is the code from the plotting class.

    Qt Code:
    1. DataPlotter::DataPlotter(QWidget *parent, QString strTitle, double minLambda, double maxLambda): QwtPlot(parent)
    2. {
    3. canvas()->setFrameStyle(QFrame::Box | QFrame::Plain );
    4. canvas()->setLineWidth(1);
    5. insertLegend(new QwtLegend(), QwtPlot::BottomLegend);
    6. setTitle(strTitle);
    7. setAxisTitle(QwtPlot::xBottom, "Wavelength (nm)");
    8. setAxisScale(QwtPlot::xBottom, minLambda, maxLambda);
    9. setAxisTitle(QwtPlot::yLeft, "Normalized Power");
    10. setAxisScale(QwtPlot::yLeft, 0, 1.2);
    11. }
    12.  
    13. void DataPlotter::addPlot(double** data, int numPoints, QString strCurveLabel)
    14. {
    15. double x[numPoints];
    16. double y[numPoints];
    17. for (int i = 0; i < numPoints; i++){
    18. x[i] = data[i][0];
    19. y[i] = data[i][1];
    20. }
    21. QwtPlotCurve *c = new QwtPlotCurve(strCurveLabel);
    22. c->setPen(QPen(Qt::red));
    23. c->attach(this);
    24. c->setData(x, y, numPoints);
    25. }
    To copy to clipboard, switch view to plain text mode 

    And here's the code calling the DataPlotter object from the main window, to update the plot:

    Qt Code:
    1. void MainWindow::drawCurvesOnPlotViewer(double** source, int numLambda, QString strTitle)
    2. {
    3. double minLambda = ui->selectMinLambda->text().toDouble();
    4. double maxLambda = ui->selectMaxLambda->text().toDouble();
    5. QString strPlotTitle = "Transmittance Plots";
    6. QLayout *layout;
    7.  
    8. // check if plotViewer QWidget already exists
    9. if (plotViewer == 0) {
    10. plotViewer = new QWidget();
    11. plotViewer->setFixedSize(500,500);
    12. plotViewer->setAttribute(Qt::WA_DeleteOnClose);
    13. connect(plotViewer, SIGNAL(destroyed()), this, SLOT(closePlot()));
    14. }
    15.  
    16. // check if DataPlotter object already exists
    17. if (blnPlot == 0) {
    18. plot = new DataPlotter(plotViewer,strPlotTitle,minLambda,maxLambda);
    19. plot->addPlot(source,numLambda,strTitle);
    20. layout = new QHBoxLayout;
    21. layout->addWidget(plot);
    22. plotViewer->setLayout(layout);
    23. blnPlot = 1;
    24. } else {
    25. plot->addPlot(source,numLambda,strTitle);
    26. }
    27.  
    28. plotViewer->show();
    29.  
    30. }
    To copy to clipboard, switch view to plain text mode 

    Any ideas as to what could be causing this? Any suggestions would be greatly appreciated, as I've been banging my head over this all day.

    Cheers!

  2. #2
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,312
    Thanked 879 Times in 827 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Odd plotting behaviour

    QwtPlot::replot is missing.

    Uwe

  3. #3
    Join Date
    May 2009
    Posts
    9
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Odd plotting behaviour

    Yep that did it, thanks very much!

Similar Threads

  1. Disable default tab behaviour for a QGraphicsItem
    By nmather in forum Qt Programming
    Replies: 3
    Last Post: 13th December 2017, 10:30
  2. Plotting specific points with qwt
    By byb810 in forum Qwt
    Replies: 0
    Last Post: 30th July 2009, 15:42
  3. Plotting from Left to Right ??
    By dheeraj in forum Qwt
    Replies: 3
    Last Post: 3rd June 2008, 07:09
  4. QAbstractItemView selection behaviour issue
    By Caius Aérobus in forum Qt Programming
    Replies: 4
    Last Post: 1st May 2007, 16:33
  5. [Qt 4.1] Strange behaviour with QTableView
    By fane in forum Qt Programming
    Replies: 1
    Last Post: 23rd January 2006, 06:17

Tags for this Thread

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.