traitsui: possible bug in spacing around view groups with QT toolkit

68 views
Skip to first unread message

Jean-Paul Davis

unread,
Jun 25, 2020, 2:45:02 PM6/25/20
to Enthought Tool Suite users
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

Josh Duran

unread,
Aug 5, 2020, 10:21:50 AM8/5/20
to Enthought Tool Suite users
I also have noticed this issue.  I'd like to add that the same issue is present when adding a traits View from another HasTraits class using Custom('trait_instance').  I have seen this issue for the generic Group class and not just the HGroup class as Jean-Paul inferred.

Kit Choi

unread,
Aug 7, 2020, 4:18:49 AM8/7/20
to Enthought Tool Suite users
Hi Jean-Paul,

Thank you very much for the report and investigation!
I agree the behaviour looks undesirable and should be an issue on the issue tracker. Would you like to open an issue on https://github.com/enthought/traitsui? Alternative I can also open it on your behalf and you can still subscribe to notifications from the issue if you have a GitHub account. Please let me know.

Best regards,
Kit

JChambless

unread,
Jan 7, 2021, 7:12:08 PM1/7/21
to Enthought Tool Suite users
Hello all,

I don't see that Jean-Paul sent a response (at least through this forum), so I wanted to say that I'm also seeing the same bug. It occurs when either enabled_when or visible_when is used. 
As Jean-Paul says, it isn't a huge issue if you are able to just set those properties in each individual Item. It doesn't work so well for labels, though. Setting an enabled_when on a Label does nothing, so it still looks enabled while everything around it is grayed out.

I will write some similar notes in the issue that Kit opened in Github (I think I have the permissions to do that...).

Thanks,
Jason
Reply all
Reply to author
Forward
0 new messages