diff --git a/spyderlib/widgets/__init__.py b/spyderlib/widgets/__init__.py
index <HASH>..<HASH> 100644
--- a/spyderlib/widgets/__init__.py
+++ b/spyderlib/widgets/__init__.py
@@ -109,19 +109,23 @@ class OneColumnTree(QTreeWidget):
         """Save all items expanded state"""

         self.__expanded_state = {}

         def add_to_state(item):

+            user_text = get_item_user_text(item)

+            self.__expanded_state[user_text] = item.isExpanded()

+        def browse_children(item):

+            add_to_state(item)

             for index in range(item.childCount()):

                 citem = item.child(index)

                 user_text = get_item_user_text(citem)

                 self.__expanded_state[user_text] = citem.isExpanded()

-                add_to_state(citem)

+                browse_children(citem)

         for tlitem in self.get_top_level_items():

-            add_to_state(tlitem)

+            browse_children(tlitem)

     

     def restore_expanded_state(self):

         """Restore all items expanded state"""

         if self.__expanded_state is None:

             return

-        for item in self.get_items():

+        for item in self.get_items()+self.get_top_level_items():

             user_text = get_item_user_text(item)

             is_expanded = self.__expanded_state.get(user_text)

             if is_expanded is not None:
Tree widgets: "expanded state" of top level items is now saved/restored (Class Browser)