标签:
1、先看效果:
现在QtChart免费了,可是老项目用的是QWT,
刚开始想的是启动时都绘制出来,自动一次次的交替显示。可是发现不可行,太卡
于是看了官方文档发现有setSamples有一个重载的方法,会自动更新就用了那个方法了。
void QwtPlotCurve::setSamples ( const QVector< QPointF > & samples )
Initialize data with an array of points.
Parameters
samples Vector of points
Note
QVector is implicitly shared
QPolygonF is derived from QVector<QPointF>
地址:http://qwt.sourceforge.net/class_qwt_plot_curve.html#a67b24f3663484ff5e973a288c6071b2a
于是就是用不停的给这线赋值。
1 // lyy : 2016/9/21 9:44:46 说明:new add QwtPlotCurve is line but not Line 2 QwtPlotCurve *m_pStraightLine; 3 QTimer *timer; 4 QDateTime dateAll; 5 6 7 8 private slots: 9 void tiemEventStart();
1 // 曲线 2 QPen RedPen (CHART_LINE_PURPLE, 2); 3 m_pStraightLine = new QwtPlotCurve ("直线"); 4 m_pStraightLine->setPen (RedPen); 5 m_pStraightLine->setRenderHint (QwtPlotItem::RenderAntialiased, true); 6 m_pStraightLine->attach (m_pQwtPlot); 7 // lyy : 2016/9/21 15:04:42 说明:connect 8 timer = new QTimer (this); 9 connect (timer, SIGNAL (timeout()), this, SLOT (tiemEventStart()));
1 void AlarmWidgetLine::tiemEventStart() 2 { 3 atempLine++; 4 QVector<QPointF> DatasListLine; 5 qreal ydata = 2; 6 qreal ydata1 = 100; 7 DatasListLine << QPointF (QwtDate::toDouble (dateAll.addSecs (atempLine * 60)), ydata); 8 DatasListLine << QPointF (QwtDate::toDouble (dateAll.addSecs (atempLine * 60)), ydata1); 9 m_pStraightLine->setSamples (DatasListLine); 10 m_pStackedWidget->setCurrentIndex (0); 11 show(); 12 }
ps:setSamples有其它的4个重载方法,其中
void QwtPlotCurve::setSamples ( const QVector< double > & xData,
const QVector< double > & yData
)
应该是一样的,没有尝试,如果看官有更好的方法,还请告诉我一下。
标签:
原文地址:http://www.cnblogs.com/ants-double/p/5894838.html