enthought / enthought/traitsui
Column widths in TabularEditor not updated when columns are changed
- Dominant language
- Python
- Stars
- 306
- Forks
- 99
- PR merge metrics
- No merged PRs in 30d
Description
If using a TabularEditor + a TabularAdapter, the column width specified in the adapter is only applied to the columns present when the editor is initialized. Any columns added later get assigned a default width. I have worked around by manually calling `resizeColumnsToContents` (https://github.com/enthought/traitsui/blob/master/traitsui/qt4/tabular_editor.py#L762) after the columns are changed in the UI (although this changes the row height also).
Toy code example:
```
from traits.api import Any, Button, HasTraits, Instance, List, on_trait_change
from traitsui.api import TabularEditor, UItem, View
from traitsui.tabular_adapter import TabularAdapter
class MyAdapter(TabularAdapter):
width = 30
alignment = 'center'
class MyViewer(HasTraits):
data = List(Any)
my_adapter = Instance(MyAdapter)
add_data = Button("Add data")
def default_traits_view(self):
self.my_adapter = MyAdapter(columns=['0', '1'])
view = View(
UItem('add_data'),
UItem(
'data',
editor=TabularEditor(
adapter=self.my_adapter,
editable=False,
stretch_last_section=False,
)
),
width=800,
height=400,
resizable=True,
)
return view
@on_trait_change('add_data')
def _add_data_to_table(self):
data = ['AAAAAA', 'BBBBBB', 'CCCCCC']
self.data = data
max_cols = max(len(s) for s in data)
self.my_adapter.columns = [str(i) for i in range(max_cols)]
if __name__ == '__main__':
viewer = MyViewer()
viewer.configure_traits()
```
Screenshot of the output that shows the issue (all columns should have same width):
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.