QCustomPlot Discussion and Comments

plotlayout is not removing the elementReturn to overview


long index=-1;
QList<QCPLayoutElement*> totalElements=chartPlot->plotLayout()->elements(false);
int size=totalElements.size();
bool isRemoved=chartPlot->plotLayout()->removeAt(size-1);
chartPlot->plotLayout()->updateLayout();
totalElements=chartPlot->plotLayout()->elements(false);
size=totalElements.size();

The plotLayout doesnot remove the last element .It just shows 0x0 for the element.
How to remove it ?

Hello God,
please read the documentation of removeAt, you will find that a call to simplify() removes empty cells.

I'm having the same issue. After removing axis rects from plot layout i am calling simplify() even though empty cells are still appearing. Any help will be helpful

+1 with The Coder. This is what I could get ,if I do removeAt(index) and then simplify . The container still holds the object. The pointers of QCPAxisRects has to be deleted one by one

void historicallayout::cleanUpWindows(){
    QCPAxisRect *rect;
    foreach(QString key,windowToAxisRectPtr.keys())
    {
        if(windowToAxisRectPtr[key]){
            rect=windowToAxisRectPtr[key];
            if(rect!=NULL){
                delete rect;
            }
        }
    };

    windowToAxisRectPtr.clear();
}

Not only this the QCPBars which are now attached to the QCPAxisRect donot get destroyed. After the previous operation. If the pointer to QCPBars are also deleted one by one like above, then chartPlot->rescaleAxes(); throws error. So the QCPBars are kept hanging without cleanup of memory