QCustomPlot Discussion and Comments

User created itemReturn to overview

Is there a way to create items when nedeed?
i want to create a line where the user choose, the problem is that the only way that i know how to create a qcpLine and text is like this

QCPItemLine *line = new QCPItemLine(ui->plot);  // do this without declaring in code first
    line->start->setCoords(x,0); // x is user defined               
    line->end->setCoords(x, 15000); // x is user defined

    // add the text label at the center top:
    QCPItemText *textLabel = new QCPItemText(ui->plot); 
    textLabel->position->setCoords(x, 0); // x is user defined, put the text label on top of the line
    textLabel->setText(" y"); //y text is user user defined
    textLabel->setFont(QFont(font().family(), 16)); 
    textLabel->setBrush(QBrush(QColor(255, 255, 255)));

       user chose 10, 20, 30, 40... 500

        line and text created at cords 10, 20,  30, 40, ...500

somethig like this F1 https://ibb.co/rygy1Jc but 4 to 50 times

you can declare a vector of QCPItemLine* and QCPItemText*, then every time you want to create a new line you do i++.

something like that

    QVector<QCPItemLine*> lines;
    QVector<QCPItemText*> Texts;

while( i < lines.size()){

    lines[i] = new QCPItemLine(ui->plot);
    lines[i]->start->setCoords(i*100,0); // make a line every 100 x values
    lines[i]->end->setCoords(i*100, 15000);

you can change the i*100 to the value that the user sended, so every time the user want to add a line will create a new QCPitemLine.

insted of the while loop you can just receive a signal when the user entered a value

something like

void MainWindow::on_comboBox_currentIndexChanged(int index)