Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Horizontal ruled separator does not appear under Groups #1312

Open
chigozienri opened this issue Oct 6, 2020 · 5 comments
Open

Horizontal ruled separator does not appear under Groups #1312

chigozienri opened this issue Oct 6, 2020 · 5 comments

Comments

@chigozienri
Copy link

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
Copy link
Contributor

rahulporuri commented Oct 6, 2020

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

# Get a panel for the Item or Group.
if isinstance(item, Group):
panel = _GroupPanel(item, self.ui, suppress_label=True).control
else:
panel = self._add_items([item])

# FIXME: all the logic for the name = '', '_', ' ', '23' magic is in
# _GroupPanel._add_items in qt/ui_panel.py, which is a very unlikely place
# to look for it. Ideally, that logic should be in this class.

@nicolasap-dm
Copy link
Contributor

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

@aaronayres35 aaronayres35 self-assigned this Mar 25, 2021
@aaronayres35
Copy link
Contributor

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
Copy link
Contributor

aaronayres35 commented Jun 23, 2021

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
Copy link
Contributor

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:

def _add_separator_item(self, item, columns, inner, row, col, show_labels):
cols = columns
# See if the layout is a grid.
if row >= 0:
# Move to the start of the next row if necessary.
if col > 0:
col = 0
row += 1
# Skip the row we are about to do.
row += 1
# Allow for the columns.
if show_labels:
cols *= 2
for i in range(cols):
line = QtGui.QFrame()
if self.direction == QtGui.QBoxLayout.LeftToRight:
# Add a vertical separator:
line.setFrameShape(QtGui.QFrame.VLine)
if row < 0:
inner.addWidget(line)
else:
inner.addWidget(line, i, row)
else:
# Add a horizontal separator:
line.setFrameShape(QtGui.QFrame.HLine)
if row < 0:
inner.addWidget(line)
else:
inner.addWidget(line, row, i)
line.setFrameShadow(QtGui.QFrame.Sunken)

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

@rahulporuri rahulporuri removed this from To be considered in Enthought OSS Q2 2021 Jul 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants