QCustomPlot Discussion and Comments

How to add a QCPItem to the QCPAxis Rect in the buttom LayoutReturn to overview

Hi,
I have a QCustomPlot with 2 QCPAxisRects in a grid layout. I want to draw a vertical line in both plots at the same x-coordinate. Since both plots have completely different areas and are zoomable, I only manage to display the two lines in the respective plot. But they are both connected to the upper QCPAxisRect. If I zoom or move something in the upper plot, the line in the lower plot is moved accordingly.
Is there a way to register or connect the lower QCPItem line with the lower layout/QCPAxisRect?

Hi,

You have to change the QCPAxisRect associated to the item. This can be done very easily with a method like this one.

void InfLineItem::moveToAxisRect(QCPAxisRect *rect) {
    setClipAxisRect(rect);
    for (auto *p : positions())
        p->setAxes(rect->axis(QCPAxis::atBottom), rect->axis(QCPAxis::atLeft));
}

InfLineItem is here a class that inherits QCPItemStraightLine.

Hope it helps.

Vincent

Hi Vincent,
Thanks a lot. This works perfectly.