From 6cd94402992d67e74abc79f5388cf2e3769e2d2e Mon Sep 17 00:00:00 2001 From: Luke Campagnola Date: Thu, 28 Sep 2017 08:56:06 -0700 Subject: [PATCH] LegendItem: make it possible to remove items directly, rather than by name --- pyqtgraph/graphicsItems/LegendItem.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/pyqtgraph/graphicsItems/LegendItem.py b/pyqtgraph/graphicsItems/LegendItem.py index 20d6416e..2c0114a7 100644 --- a/pyqtgraph/graphicsItems/LegendItem.py +++ b/pyqtgraph/graphicsItems/LegendItem.py @@ -81,19 +81,19 @@ class LegendItem(GraphicsWidget, GraphicsWidgetAnchor): self.layout.addItem(label, row, 1) self.updateSize() - def removeItem(self, name): + def removeItem(self, item): """ Removes one item from the legend. ============== ======================================================== **Arguments:** - title The title displayed for this item. + item The item to remove or its name. ============== ======================================================== """ # Thanks, Ulrich! # cycle for a match for sample, label in self.items: - if label.text == name: # hit + if sample.item is item or label.text == item: self.items.remove( (sample, label) ) # remove from itemlist self.layout.removeItem(sample) # remove from layout sample.close() # remove from drawing @@ -130,7 +130,8 @@ class LegendItem(GraphicsWidget, GraphicsWidgetAnchor): if ev.button() == QtCore.Qt.LeftButton: dpos = ev.pos() - ev.lastPos() self.autoAnchor(self.pos() + dpos) - + + class ItemSample(GraphicsWidget): """ Class responsible for drawing a single item in a LegendItem (sans label).