我需要从布局中清除我的 chartViewers,但是当我这样做时,我无法删除最后一个小部件。当我测试布局的长度时,我得到 0 但在更新布局后小部件仍然存在,如图所示:
这是我删除时的代码,小部件和图表
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)
这是我创建图形并将其添加到布局的代码:
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])
有什么建议吗?