enthought/traitsui

TreeEditor causes a segmentation fault during a drag event

Closed this issue · 1 comments

When I try to click and drag a tree node, on the first click and drag, it move the selection along with my mouse. This is fine. I haven't implemented any drag behavior, so I don't expect anything special to happen.

However, it also logs to the console the following,

Traceback (most recent call last):
  File "/Users/mreay/.edm/envs/tree_editor_demo/lib/python3.8/site-packages/traitsui/qt4/tree_editor.py", line 1554, in startDrag
    option = self.viewOptions()
AttributeError: '_TreeWidget' object has no attribute 'viewOptions'

On the second attempt, however, I get the following error, and the application closes with a segmentation fault.

QPaintDevice: Cannot destroy paint device that is being painted
zsh: segmentation fault  python sandbox/tree_editor_demo.py

NOTE: While making the below gif, I also got this error instead.. But it's usually the segmentation fault.

QPaintDevice: Cannot destroy paint device that is being painted
libc++abi: Pure virtual function called!
zsh: abort      python sandbox/tree_editor_demo.py

Gif showing what happens in the window,

Complete output of the console
tree_editor_demo ❯ python sandbox/tree_editor_demo.py
Traceback (most recent call last):
  File "/Users/mreay/.edm/envs/tree_editor_demo/lib/python3.8/site-packages/traitsui/qt4/tree_editor.py", line 1554, in startDrag
    option = self.viewOptions()
AttributeError: '_TreeWidget' object has no attribute 'viewOptions'
QPaintDevice: Cannot destroy paint device that is being painted
zsh: segmentation fault  python sandbox/tree_editor_demo.py
Environment used to run the sample (Python 3.8)
tree_editor_demo ❯ edm freeze
importlib_resources  5.4.0-1
libfreetype          2.12.1-1
libharfbuzz          3.2.0-4
libicu               70.1-2
libpng               1.6.37-100
libturbojpeg         2.1.2-1
libzstd              1.5.0-1
pip                  22.2.2-1
pyface               7.4.2-2
pyside6              6.2.3-6
qtbase               6.2.3-3
qtdeclarative        6.2.3-2
qtmultimedia         6.2.3-3
qtshadertools        6.2.3-2
qtsvg                6.2.3-2
qttools              6.2.3-3
setuptools           57.0.0-3
shiboken6            6.2.3-4
traits               6.4.1-1
traitsui             7.4.2-1
zipp                 3.7.0-1
Sample used to generate this error
from traits.api import HasTraits, Str, List, Instance

from traitsui.api import Item, View, TreeEditor, TreeNode, ModelView


class Employee(HasTraits):
    """Defines a company employee."""

    name = Str('<unknown>')


class Company(HasTraits):
    """Defines a company with departments and employees."""

    name = Str('<unknown>')
    employees = List(Employee)


class CompanyView(ModelView):
    """Defines a business partner."""

    model = Instance(Company)

    def default_traits_view(self):
        return View(
            Item(
                name='model',
                editor=TreeEditor(
                    nodes=[
                        TreeNode(
                            node_for=[Company],
                            auto_open=True,
                            label='name',
                            children='employees',
                            view=View(),
                        ),
                        TreeNode(
                            node_for=[Employee],
                            label='name',
                            view=View(),
                        ),
                    ]
                ),
                show_label=False,
            ),
            title='Company Structure',
            buttons=['OK'],
            resizable=True,
            style='custom',
            width=0.3,
            height=500,
        )

# Create the demo:
demo = CompanyView(
    model=Company(
        name='Enthought',
        employees=[
            Employee(name='Dave'),
            Employee(name='Jason'),
            Employee(name='Mike')
        ],
    ),
)

# Run the demo (if invoked from the command line):
if __name__ == '__main__':
    demo.configure_traits()

Thanks - this looks like a Qt API change on QAbstractItemView between Qt5 and Qt6.

Not sure what the fix/work-around is yet.