Though I have "solved" this problem by a simple work-around, I thought it was worth posting here as a potential bug in traitsui, so that a developer might verify that it really is a bug and turn it into an official issue. I came across the problem four years ago while writing a complex traitsui-based application (in Python 2.7 using whatever were the latest versions of traits and traitsui at the time), and since it occurred only when using the qt4 toolkit, not the wx toolkit, I simply stuck with wx for my application. Recently, I made the change to Python 3.6, and since traitsui 7 does not yet fully support wxpython (which is not available on Enthought's repositories via edm, and attempts to install via pip fail), I am now using the qt5 toolkit. The problem I originally observed with traitsui and qt4 still exists with qt5; therefore, I made the effort to pin down exactly what conditions cause it.
The problem is this: specifying the "enabled_when" keyword argument to a Group adds extra space in the layout around the Group. Specifying this keyword for each individual item in the group produces the expected behavior (no extra space added), and thus constitutes a simple work-around. The use-case for desiring specification of "enabled_when" at the Group level is when there are multiple items (in my case seven VGroups, each containing a Label and an Item) that need to be enabled/disabled by a single condition, particularly when display of this Group is expected to align with other Groups in the View. I expect that the Group-level specification can be overridden at the Item level to produce the behavior where some of the individual items require a different condition. Below is the shortest code I have been able to write that reproduces the issue.
from traits.api import HasTraits, Float
from traitsui.api import Item, View, HGroup, VGroup
class MyApp(HasTraits):
a = Float(1.0)
traits_view = View(
VGroup(
# enabled_when for Group inserts extra space around group
HGroup(Item('a'), enabled_when='True'),
# enabled_when for individual item inside Group does not
HGroup(Item('a', enabled_when='True'))
)
)
app = MyApp()
app.configure_traits()
At least on my system (RHEL 7, Python 3.6.10, qt 5.12.6, pyqt5 5.14.2, pyface 7.0.0, traits 6.1.0, traitsui 7.0.0), this creates a window with extra space around the first HGroup but not the second HGroup. I have not tested the above code on other platforms, but I do recall that the problem occurred as well under Windows back when I was using Python 2.7 and qt4. I just realized I also have not tested it using VGroup instead of HGroup, but I would be surprised if the problem weren't in the base Group class.
Jean-Paul Davis