eric7/EricWidgets/EricIconBar.py

branch
eric7
changeset 8724
6ee36599a1f8
parent 8591
7cf4b7bc3d5a
child 8725
842ba8a9dbbb
diff -r 0338c9ad59af -r 6ee36599a1f8 eric7/EricWidgets/EricIconBar.py
--- a/eric7/EricWidgets/EricIconBar.py	Tue Oct 26 17:06:36 2021 +0200
+++ b/eric7/EricWidgets/EricIconBar.py	Tue Oct 26 17:42:19 2021 +0200
@@ -272,9 +272,13 @@
         """
         label = self.__layout.itemAt(index)
         if label:
-            self.__layout.removeWidget(label.widget())
+#            self.__layout.removeItem(label)
+#            self.__layout.removeWidget(label.widget())
             with contextlib.suppress(IndexError):
                 del self.__icons[index]
+            itm = self.__layout.takeAt(index)
+            itm.widget().deleteLater()
+            del itm
             
             if index == self.__currentIndex:
                 self.setCurrentIndex(index)
@@ -290,10 +294,11 @@
         @type EricClickableLabel
         """
         index = self.__layout.indexOf(label)
-        if index == self.__currentIndex:
-            self.currentClicked.emit(self.__currentIndex)
-        else:
-            self.setCurrentIndex(index)
+        if index >= 0:
+            if index == self.__currentIndex:
+                self.currentClicked.emit(self.__currentIndex)
+            else:
+                self.setCurrentIndex(index)
     
     def setCurrentIndex(self, index):
         """
@@ -305,11 +310,13 @@
         if index >= self.count():
             index = -1
         
-        if index != self.__currentIndex:
+        if index != self.__currentIndex and index >= 0:
             # reset style of previous current icon
             oldLabel = self.__layout.itemAt(self.__currentIndex)
             if oldLabel:
-                oldLabel.widget().setStyleSheet("")
+                widget = oldLabel.widget()
+                if widget is not None:
+                    widget.setStyleSheet("")
             
             # set style of new current icon
             newLabel = self.__layout.itemAt(index)

eric ide

mercurial