T
T
tschin2015-06-28 21:59:52
Qt
tschin, 2015-06-28 21:59:52

How to display multiple QwtPlotCurve plots?

Hello! I'm trying to display multiple plots on QwtPlotCurve. Everything seems to be fine, but the charts are displayed only after the delay (Sleep(1000)) is executed after each call to the function of adding data to the chart.
function to add a graph to the drawing field

void Widget::GetCurve(QwtPlot *plot, Qt::GlobalColor colorLine)
{
    QwtPlotCurve *curve;
    QwtSymbol *symbol;
    QPolygonF *points;
    curve=new QwtPlotCurve();
    symbol= new QwtSymbol( QwtSymbol::Ellipse,
                           QBrush( Qt::yellow ), QPen( Qt::red, 2 ), QSize( 8, 8 ) );
    points = new QPolygonF;
    curve->setTitle("Demo Curve");
    curve->setPen(colorLine, 6); // цвет и толщина кривой
    curve->setRenderHint(QwtPlotItem::RenderAntialiased, true); // сглаживание
    curve->setSymbol(symbol);
    listCurve.append(curve);
    listCurve.last()->attach(plot);
}

function for adding data to the chart:
void Widget::AppendSamples()
{
    QVector<double> x;
    QVector<double> y;
    QList<QPointF> listPoint =  ReturnPointsList(150);
    int listPointCount = listPoint.count();  
    for (int i=0;i<listPointCount;i++)
    {
        x.append(listPoint[i].x());
        y.append(listPoint[i].y());
    }
     listCurve.last()->setSamples(x,y);
}

How it's all used:
GetCurve(listPlot.last(),Qt::red);
        AppendSamples();
       // Sleep::Sleeper(ms);
        GetCurve(listPlot.last(),Qt::green);
        AppendSamples();
        //Sleep::Sleeper(ms);
        GetCurve(listPlot.last(),Qt::black);
        AppendSamples();
       // Sleep::Sleeper(ms);
       listPlot.last()->replot();

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vitaly, 2015-06-28
@vt4a2h

I haven't worked with this component, but most likely the problem is that replot() needs to be called after each addition of a new curve, or setAutoReplot(true) on QwtPlot after object creation (although the first option is probably better).

D
DancingOnWater, 2015-06-29
@DancingOnWater

After calling replot, you should be in the event loop. Is this happening to you?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question