Results 1 to 4 of 4

Thread: Repaint QSplineSeries

  1. #1
    Join Date
    Jul 2016
    Posts
    41
    Thanks
    2
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Repaint QSplineSeries

    Hello!

    I would like dynamically rewrite chart, generated by QSplineSeries.
    I am trying to achieve it this way:

    Qt Code:
    1. QSplineSeries* series_for_Vy= new QSplineSeries();
    2. QChart* chart_for_Vy = new QChart();
    3. QGroupBox *Widget::set_splinechart_Vy()
    4. {
    5.  
    6. int n ; //номер шага по времени
    7. number_of_step_for_Vy = new QLineEdit("steps");
    8.  
    9. series_for_Vy->append(3,3);
    10. series_for_Vy->append(2,5);
    11.  
    12. chart_for_Vy->legend()->hide();
    13. chart_for_Vy->addSeries( series_for_Vy);
    14. chart_for_Vy->setTitle("Vy (N)");
    15. chart_for_Vy->createDefaultAxes();
    16. chart_for_Vy->axisY()->setRange(0, 10);
    17. chart_for_Vy->axisX()->setRange(0,10);
    18. chart_for_Vy->axisX()->setTitleText("Number of Node, N");
    19. chart_for_Vy->axisY()->setTitleText("Velocity, Vy");
    20.  
    21.  
    22.  
    23. QChartView *chartView = new QChartView(chart_for_Vy);
    24.  
    25.  
    26. slider_for_Vy = new QSlider(Qt::Orientation::Horizontal);
    27. slider_for_Vy->setRange(1,999);
    28.  
    29.  
    30. QVBoxLayout *vert = new QVBoxLayout;
    31. QHBoxLayout *horiz = new QHBoxLayout;
    32. vert->addWidget(chartView);
    33. // vert->addWidget(slider);
    34. horiz->addWidget(slider_for_Vy,Qt::AlignLeft);horiz->addWidget(number_of_step_for_Vy);
    35. vert->addLayout(horiz);
    36. QGroupBox* groupbox = new QGroupBox("Y-component of velocity");
    37. groupbox->setLayout(vert);
    38. //connect(number_of_step_for_Vy,SIGNAL(textEdited(QString)),SLOT(update()));
    39. return groupbox;
    40. }
    41.  
    42. void Widget::plot_Velocity_Y()
    43. {
    44. series_for_Vy->clear();
    45. series_for_Vy->append(3,3);
    46. series_for_Vy->append(2,9);
    47. chart_for_Vy->clearFocus();
    48. chart_for_Vy->addSeries( series_for_Vy);
    49.  
    50. }
    To copy to clipboard, switch view to plain text mode 

    But when program comes to SLOT plot_Velocity_Y, it does not change and lines appear:
    "Can not add series. Series already on the chart."

    How to handle this?

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,316
    Thanks
    315
    Thanked 870 Times in 857 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Repaint QSplineSeries

    You're trying to add the same series more than once (that is, QSplineSeries * series_for_Vy has already been added to the chart). The fact that you changed the data in the series makes no difference.

    You probably need to do this:

    - remove the series from the chart (QChart::removeSeries())
    - change the series data
    - add the series back to the chart (QChart::addSeries())

    You may not actually need to remove and add the series, but from what I remember of QChart, changing the data in the series may not result in an update to the chart.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  3. #3
    Join Date
    Jul 2016
    Posts
    41
    Thanks
    2
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Repaint QSplineSeries

    Thank you!

  4. #4
    Join Date
    May 2011
    Posts
    81
    Thanks
    6
    Thanked 5 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11

    Thumbs up Re: Repaint QSplineSeries

    I'm using QML for my charts, but I have been able to achieve updating the series without removing and recreating it...

    Qt Code:
    1. wavgSeries.remove(0);
    2. wavgSeries.append(appWin.wxMsec,appWin.wxWavg);
    To copy to clipboard, switch view to plain text mode 

    Basically, removing the first element in the series, then just appending a new one...

    --SamG

  5. The following user says thank you to scgrant327 for this useful post:

    d_stranz (15th May 2017)

Similar Threads

  1. Replies: 4
    Last Post: 17th October 2010, 22:30
  2. repaint widget
    By yxtx1984 in forum Newbie
    Replies: 4
    Last Post: 11th March 2010, 03:51
  3. Use of repaint/update
    By Placido Currò in forum Qt Programming
    Replies: 3
    Last Post: 3rd April 2007, 19:24
  4. Repaint Widget in an other
    By hubert_p in forum Qt Programming
    Replies: 7
    Last Post: 6th November 2006, 12:12
  5. repaint help pls
    By munna in forum Qt Programming
    Replies: 3
    Last Post: 21st June 2006, 10:52

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
  •  
Qt is a trademark of The Qt Company.