From 74e8b29972779f1beadd50afe9bbcbe1be37d0a8 Mon Sep 17 00:00:00 2001 From: Aaron Ayres Date: Wed, 30 Jun 2021 13:00:43 -0500 Subject: [PATCH 1/2] add new update_column_widths event trait to call resizeColumnsToContents --- traitsui/qt4/tabular_editor.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/traitsui/qt4/tabular_editor.py b/traitsui/qt4/tabular_editor.py index da20ac780..1a578272a 100644 --- a/traitsui/qt4/tabular_editor.py +++ b/traitsui/qt4/tabular_editor.py @@ -30,6 +30,7 @@ Int, List, NO_COMPARE, + observe, Property, TraitListEvent, ) @@ -72,6 +73,9 @@ class TabularEditor(Editor): #: The event fired when a simple repaint is needed: refresh = Event() + #: The event fired when a recompute of column widths is needed + update_column_widths = Event() + #: The current set of selected items (which one is used depends upon the #: initial state of the editor factory 'multi_select' trait): selected = Any() @@ -535,6 +539,10 @@ def _scroll_to_column_changed(self, column): self.model.index(max(self.selected_row, 0), column), scroll_hint ) + @observe("update_column_widths", post_init=True) + def _resize_columns_on_event(self, event): + self.control.resizeColumnsToContents() + # -- Table Control Event Handlers ----------------------------------------- def _on_activate(self, index): From dae4436d12236f61323037418e856a7d46f96f38 Mon Sep 17 00:00:00 2001 From: Aaron Ayres Date: Wed, 30 Jun 2021 13:16:09 -0500 Subject: [PATCH 2/2] undo previous change and now when update is fired, if auto_resize is set, call resizeColumnsToContents() --- traitsui/qt4/tabular_editor.py | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/traitsui/qt4/tabular_editor.py b/traitsui/qt4/tabular_editor.py index 1a578272a..c672f67b7 100644 --- a/traitsui/qt4/tabular_editor.py +++ b/traitsui/qt4/tabular_editor.py @@ -30,7 +30,6 @@ Int, List, NO_COMPARE, - observe, Property, TraitListEvent, ) @@ -73,9 +72,6 @@ class TabularEditor(Editor): #: The event fired when a simple repaint is needed: refresh = Event() - #: The event fired when a recompute of column widths is needed - update_column_widths = Event() - #: The current set of selected items (which one is used depends upon the #: initial state of the editor factory 'multi_select' trait): selected = Any() @@ -413,6 +409,8 @@ def _adapter_columns_updated(self): def _update_changed(self): self.update_editor() + if self.factory.auto_resize: + self.control.resizeColumnsToContents() def _refresh_changed(self): self.refresh_editor() @@ -539,10 +537,6 @@ def _scroll_to_column_changed(self, column): self.model.index(max(self.selected_row, 0), column), scroll_hint ) - @observe("update_column_widths", post_init=True) - def _resize_columns_on_event(self, event): - self.control.resizeColumnsToContents() - # -- Table Control Event Handlers ----------------------------------------- def _on_activate(self, index):