@@ -558,13 +558,27 @@ def set_central_widget(self, name):
558558 ----------
559559 name: str or QWidget
560560 The key or the plugin widget in the :attr:`plugins` dictionary"""
561+ from PyQt5 .QtCore import QTimer
562+ self .setUpdatesEnabled (False )
561563 current = self .centralWidget ()
562564 if isinstance (name , six .string_types ):
563565 new = self .plugins [name ]
564566 else :
565567 new = name
566568 name = next (key for key , val in self .plugins .items () if val is new )
567569 if new is not current :
570+
571+ self ._dock_widths = dock_widths = OrderedDict ()
572+ self ._dock_heights = dock_heights = OrderedDict ()
573+ for key , w in self .plugins .items ():
574+ if w .dock is not None and w .is_shown :
575+ s = w .dock .size ()
576+ dock_widths [w ] = s .width ()
577+ if w is not new :
578+ dock_heights [w ] = s .height ()
579+
580+ new_pos = self .dockWidgetArea (new .dock )
581+
568582 self .removeDockWidget (new .dock )
569583 new .dock .close ()
570584 self .panes_menu .removeAction (new ._view_action )
@@ -576,8 +590,28 @@ def set_central_widget(self, name):
576590 new ._set_central_action .setChecked (True )
577591 current .show_plugin ()
578592 current .to_dock (self )
593+ new_width = dock_widths .pop (new )
579594 if current .hidden :
580595 current .hide_plugin ()
596+ else :
597+ current_pos = self .dockWidgetArea (current .dock )
598+ if current_pos == new_pos :
599+ dock_widths [current ] = new_width
600+
601+ self ._custom_layout_timer = QTimer (self )
602+ self ._custom_layout_timer .timeout .connect (self ._reset_dock_widths )
603+ self ._custom_layout_timer .setSingleShot (True )
604+ self ._custom_layout_timer .start (5000 )
605+
606+ def _reset_dock_widths (self ):
607+ # resize the plugins
608+ if with_qt5 :
609+ for w , width in self ._dock_widths .items ():
610+ self .resizeDocks ([w .dock ], [width ], Qt .Horizontal )
611+ for w , height in self ._dock_heights .items ():
612+ self .resizeDocks ([w .dock ], [height ], Qt .Vertical )
613+
614+ self .setUpdatesEnabled (True )
581615
582616 def _save_project (self , p , new_fname = False , * args , ** kwargs ):
583617 if new_fname or 'project_file' not in p .attrs :
0 commit comments