How to display a nested list on the UI?

There is an add-on that I’m contributing to and I would to improve the UI. The add-on works with a two-level deep nested list (list>sublist>item), currently the add-on is using 2 UIlists, on the first one it show the sublists and when you select one of these their items are displayed on the second list. I think it will be better to display it in a single collapsible list, like the Outliner http://www.blender.org/manual/editors/outliner.html

if the outliner can do it the community add-ons should be able to do it too, the problem is the poor and outdated documentation for the developers.

Anyone knows how to use that UI Widget?

Hello lordscales91,

Currently, I’m facing the issue. Have you managed to find any solution for that?.

Thanks,
Mostafa

The UIList class (https://docs.blender.org/api/current/bpy.types.UIList.html) does not support this functionality.

However, nested UIList items can be “faked”. The Collection Manager built-in add-on has nesting implemented, so you could study its source and see if its approach fits your requirements.

Nevertheless, you will not be able to easily mimic the outliner because the UIList can’t display items of different types. So you can’t have a list that displays Collections and then have Objects nested under them. This can be worked around though by creating a PropertyGroup and displaying its items instead. These items would then have a StringProperty that would indicate which type it represents, and then in the draw_item method of the UIList, depending on the stored data type you would fetch the required info from bpy.data and display it.