def selectionChanged(self):
for i in range(self.left_customPlot.graphCount()):
graph = self.left_customPlot.graph(i)
item = self.left_customPlot.legend.itemWithPlottable(graph)
if item.selected():
item.setSelected(True)
graph.setSelection(QCPDataSelection(graph.data().dataRange()))
self.left_customPlot.update()
此代码从c++转换成python代码,c++代码正常运行,python代码在item.setSelected(True) 报错RuntimeError: Internal C++ object (QCustomPlot.QCPPlottableLegendItem) already deleted.