diff --git a/pyqtgraph/graphicsItems/PlotItem/PlotItem.py b/pyqtgraph/graphicsItems/PlotItem/PlotItem.py index 2158b1a1..f3849b99 100644 --- a/pyqtgraph/graphicsItems/PlotItem/PlotItem.py +++ b/pyqtgraph/graphicsItems/PlotItem/PlotItem.py @@ -563,8 +563,8 @@ class PlotItem(GraphicsWidget): if item in self.dataItems: self.dataItems.remove(item) - if item.scene() is not None: - self.vb.removeItem(item) + self.vb.removeItem(item) + if item in self.curves: self.curves.remove(item) self.updateDecimation() diff --git a/pyqtgraph/graphicsItems/ViewBox/ViewBox.py b/pyqtgraph/graphicsItems/ViewBox/ViewBox.py index 6c6e3718..9c71d7db 100644 --- a/pyqtgraph/graphicsItems/ViewBox/ViewBox.py +++ b/pyqtgraph/graphicsItems/ViewBox/ViewBox.py @@ -399,10 +399,12 @@ class ViewBox(GraphicsWidget): """ if item.zValue() < self.zValue(): item.setZValue(self.zValue()+1) + scene = self.scene() if scene is not None and scene is not item.scene(): scene.addItem(item) ## Necessary due to Qt bug: https://bugreports.qt-project.org/browse/QTBUG-18616 item.setParentItem(self.childGroup) + if not ignoreBounds: self.addedItems.append(item) self.updateAutoRange() @@ -413,7 +415,12 @@ class ViewBox(GraphicsWidget): self.addedItems.remove(item) except: pass - self.scene().removeItem(item) + + scene = self.scene() + if scene is not None: + scene.removeItem(item) + item.setParentItem(None) + self.updateAutoRange() def clear(self):