Qwt 6.1 legend duplication



  • my code:
    @
    void MainWindow::drawGraphCpuGeneralSlot(int cpu)
    {
    int graphTimeInt = ui->spinBox->value();
    double graphTimeDouble = (double) graphTimeInt;

    QwtLegend *legend = new QwtLegend();
    
    ui->graphCPU->setTitle(QString::fromUtf8("cpu"));
    ui->graphCPU->insertLegend(legend);
    ui->graphCPU->setFooter("seconds");
    ui->graphCPU->setAxisScale(QwtPlot::xBottom,0.0,graphTimeDouble);
    ui->graphCPU->setAxisTitle(QwtPlot::yLeft,QString::fromUtf8("%"));
    ui->graphCPU->setAxisScale(QwtPlot::yLeft,0.0,100.0);
    
    cpuLine = new QwtPlotCurve(QString(""));
    cpuLine->setPen(QPen(Qt::darkGreen, mainLineInGraph));
    cpuLine->setTitle("usage - " + QString::number(cpu));
    
    this->cpuArray[0] = cpu;
    
    cpuLine->setRawSamples(this->cpuArrayTime,this->cpuArray,myIterator);
    cpuLine->attach(ui->graphCPU);
    
    for(int i=myIterator;i!=0;i--) {
    this->cpuArray[i] = this->cpuArray[i-1];
    }
    

    }
    @

    it is slot funtion. Slot is working, but legend is duplicating:
    http://farm8.staticflickr.com/7380/11495605866_817e00069c.jpg

    what's my be wrong? Thank you.



  • Guess the legend is o.k. but you are creating/attaching another curve with the same title by accident with each data update.



  • [quote author="uwer" date="1387730153"]Guess the legend is o.k. but you are creating/attaching another curve with the same title by accident with each data update.[/quote]

    Yes, I divided this function to two functions: one for initializing and one for updating. Now it works file. Thank you :)


  • Moderators

    @alex2323
    welcome to devnet

    I have added "code wrappings (please see forum help)":http://qt-project.org/wiki/ForumHelp#e3f82045ad0f480d3fb9e0ac2d58fb01 to your original post. Please use them next time you have a code section in your post.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.