c++qtqt5qcustomplot

QCPItemLine is being paint automatically


Im trying using QCustomPlot in my gui

MainWindow.h

public:
void initArrow();

private:
QCustomPlot* grid;
QCPItemLine* arrow;

MainWindow.cpp

void MainWindow::initArrow() {
arrow = new QCPItemLine(ui->grid);
QPen pen(Qt::red);
pen.setWidth(4);

arrow->setPen(pen);
arrow->setHead(QCPLLineEnding::esLineArrow);
arrow->setHead(QCPLLineEnding::esDisc);
}

in this situation i'm playing the program, i resize the window and i see an arrow on the plot with coordinates (0,0) and (1,1). this is the code . I didnt use replot! I didnt use start! I didnt use end!

in addition, when i will understand what is the problem I'm asking what is the correct way to draw a line when i'm trying to draw above other graph.

normally if I'm using points it will be like:

QVector<double> x;
QVector<double> y;
ui->grid->graph(number)->setData(x,y);
ui->grid->graph(number)->replot();

but I cant do setData with a line and its not related to some graph so i can i Draw the line on a specefic graph??


Solution

  • QCPItemLine is drawn automatically without replot, if you want it not to be displayed you must use:

    setVisible(False);
    

    If you want it to be displayed use:

    setVisible(True);
    ui->grid->replot();