QCustomPlot Discussion and Comments

QCPItemStraightLine - a potential bug?Return to overview

Hi all, I've spent a few hours trying to figure this one out and I'm exhausted. If I have multiple axes with graphs in my plot, and I try to add a a QCPItemStraightLine to axes after the first one, they all end up on the first axis!

The code i'm using is like this:

QCPItemStraightLine* l = new QCPItemStraightLine(ui->plot);
l->point1->setType(QCPItemPosition::ptPlotCoords);
l->point2->setType(QCPItemPosition::ptPlotCoords);
l->point1->setAxes(graph->keyAxis(), graph->valueAxis());
l->point2->setAxes(graph->keyAxis(), graph->valueAxis());
l->point1->setCoords(0.0, value);
l->point2->setCoords(1.0, value);

where graph is one of ui->plot->graph(i), for i greater than 0.

If it's not clear, by multiple axes, I mean I have several graphs stacked vertically. The graphs are fine, but if I draw lines on the lower graphs, they are actually displayed in the topmost graph.

Ahh, I finally solved it! You have to call:

l->setClipAxisRect(axisRect);

where axisRect is the QCPAxisRect containing the two axes. I think it's not very clear in the documentation how to do this use case.

Cheers
PS. you should have a donate link somewhere, this package is amazing!

Thanks for the feedback. I'll find a way to reduce the potential to confuse people. Either by setting a sensible default (e.g. just clip to the main axis rect by default... but then again the lines would've been invisible in all but the first axis rect), or by mentioning more centrally somewhere, that the clipping must be set manually to a certain axis rect.