QCustomPlot Discussion and Comments

Drawing vertical straight lineReturn to overview

I'm trying to draw a simple straight vertical line. Since these methods dont work:

QCPItemLine *line = new QCPItemLine(customPlot);
line->point1->setCoords(2, 0);  // location of point 1 in plot coordinate
line->point2->setCoords(2, 1);  // location of point 2 in plot coordinate

nor this:

QCPItemLine *min1 = new QCPItemLine(ui->plot);
 
min1->setSelectable(true);
 
//Adding the vertical lines to the plot
ui->plot->addItem(min1);
min1->start->setCoords(x01, -1e7);
min1->end->setCoords(x01, 1e7);

is there any other way to do that?

Already the first method you show works. Did you load the item example? It also contains a line.

Probably your axis ranges are different so it's just not in the visible section, or you forgot to call replot

When I write:

QCPItemLine *line = new QCPItemLine(ui->myWidget);
line->point1->setCoords(2, 0); 

Error is:
error: C2039: 'point': is not a member of 'QVector<qreal>'

Any idea why is this showing?