I need, to clear my chartViewers from a layout, but when I do, I can't delete the last widget. when I test the length of my layout, I get 0 but the widget is still here after update of the layout, as in the picture :
here my code when I delete, the widgets and the graphs
print("proceding to delete chart ", chartName, " at : ", indexGraph)
currentGraph = self.charts[indexGraph]
currentWidget = self.chartVs[indexGraph]
self.chartLayout.removeWidget(currentWidget)
self.chartVs.remove(currentWidget)
currentGraph.clearData()
self.charts.remove(currentGraph)
self.chartLayout.update()
#currentWidget.resetCachedContent()
listGraphs.remove(chartName)
self.refreshListWithOpt(self.chartTree, listGraphs, 1, optGraphs)
and here is the code where I create the graphs and add it to the layout:
self.charts.append(chartClass(patientStr, exp))
print("\nNew Plot chart ", self.charts[lastIndex].name, " length : ", lastIndex )
listGraphs.append(self.charts[lastIndex].name)
print("list Graphs : ", listGraphs)
self.charts[lastIndex].plotJSON(myData.plot(patientStr, exp))
self.chartVs.append(QChartView(self.charts[lastIndex]))
self.chartVs[lastIndex].setRenderHint(QPainter.Antialiasing)
self.chartLayout.insertWidget(0, self.chartVs[lastIndex])
Any suggestion?
When a widget is added to the main widget the default position is 0, 0, when we add it to a layout this position is handled by it, so if we remove it from the layout it will return to its initial position, visually generating the effect of not being delete, then to solve it we must delete the widget for it we use the method deleteLater()