enthought / traitsui

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

Horizontal ruled separator does not appear under Groups #1312

Open chigozienri opened 4 years ago

chigozienri commented 4 years ago

Item('_') does not produce a visible separator when immediately underneath a Group To replicate:

from traits.api import *
from traitsui.api import *

class SeparatorTest(HasTraits):
    view = View(
        Label('Above'),
        Item('_'),
        Label('Below'),
        Item('_'),
        Group(Label('Caverns')),
        Item('_'),
        Group(Label('Dungeons')),
        Item('_'),
        Group(Label("Extra dungeons")),
        Item('_'),
        Label('Foundations')
    )

if __name__ == "__main__":
    separator = SeparatorTest()
    separator.configure_traits()
separator
rahulporuri commented 4 years ago

@nicolasap-dm points to these locations as being the potential sources of error -

https://github.com/enthought/traitsui/blob/94da89c3199d033f231990dd3c783253a6260dd6/traitsui/qt4/ui_panel.py#L631-L635 https://github.com/enthought/traitsui/blob/ca847133947e5ad41f6bb55942c5c9ed64d80bbe/traitsui/item.py#L91-L93

nicolasap-dm commented 4 years ago

(I haven't followed the whole logic there, so they may be completely misguided. On the surface, however, the snippets look relevant.)

aaronayres35 commented 3 years ago

Looking into this a bit it seems as though the separator is there, it just gets covered by a subsequent group(?). The last separator which is followed by a Label is shown even though it comes after a group. Also if you remove one of the separators between groups you can see that the 2 groups are shown closer together. i.e. the Item("-") is there separating the groups, but the corresponding sunken line is not visible

aaronayres35 commented 3 years ago

Note, as a workaround I believe moving the separator inside the group "fixes" this: ie replacing

Group(Label('Caverns')),
Item('_'),

with

Group(
    Label('Caverns'),
    Item('_'),
),

yields

Screen Shot 2021-06-23 at 4 10 13 PM
aaronayres35 commented 3 years ago

I believe the error here is really whenever a separator is the only Item in a Group (even an implicit group). In practice this would occur is you have Item('_') directly between two groups, or did something like Group(Item('_')). In this scenario we end up setting up a QGridLayout with just the QtGui.QFrame.HLine in it. See: https://github.com/enthought/traitsui/blob/20f73e83b1424dd86b28de4537c2fe35beca331c/traitsui/qt4/ui_panel.py#L1008-L1043

With nothing else in the layout I believe what is happening is the HLine effectively has no length. It is still there though, and we can see this because if we remove a separator between groups the 2 groups are shown much closer together:

Screen Shot 2021-06-24 at 9 02 21 AM

So the separators are there but the line isn't visible.

Unfortunately I am not seeing an easy / clean way to fix this... I think the best solution is to just pull the separator up into the end of the first group rather than between 2 groups.

If this workaround solves the problem, I think it is safe to close this issue