enthought / traitsui

TraitsUI: Traits-capable windowing framework
http://docs.enthought.com/traitsui
Other
297 stars 95 forks source link

Stretchy tabular editor makes last column way too wide #667

Open notmatthancock opened 4 years ago

notmatthancock commented 4 years ago

If stretch_last_section=True (the default) for the TabularEditor, the resulting table has a final column which is exceedingly wide:

Example:

from traits.api import *
from traitsui.api import *
from traitsui.tabular_adapter import TabularAdapter

class Person(HasTraits):
    name = Str
    age = Int

class PersonAdapter(TabularAdapter):
    columns = [('Name', 'name'), ('Age', 'age')]

class People(HasTraits):
    persons = List(Instance(Person))

    def _persons_default(self):
        return [Person(name=f'Bob-{i}', age=i) for i in range(32)]

    traits_view = View(
        UItem(
            'persons',
            editor=TabularEditor(
                adapter=PersonAdapter(),
                stretch_last_section=True,
            ),
        ),
        width=300,
        resizable=True,
    )

if __name__ == '__main__':
    People().configure_traits()

Result with stretch_last_section=True

image

Result with stretch_last_section=False

image

corranwebster commented 4 years ago

Thanks for the report - looks like a bad interaction between Qt and the new column sizing code.

The work-around is to turn off stretch_last_section and specify the widths of all but the last column, eg.

class PersonAdapter(TabularAdapter):
    columns = [('Name', 'name'), ('Age', 'age')]

    name_width = Int(100)

should give you close to what you want.

Not sure if the right solution here is to deprecate stretch last section, or to work out how to account for it in the layout code.

notmatthancock commented 4 years ago

Thanks for the suggestion. We'll probably just leave it at stretch_last_section=False and leave resizing up to the user.