I created a ui list in which each item in the list has 3 properties--name, type, and number. In the list in my panel, I would like to have the type and number, but not the name. Here is my Python code:
import bpy
from bpy.types import PropertyGroup, UIList, Operator, Panel
from bpy.props import StringProperty, FloatProperty, CollectionProperty, IntProperty
class CustomItem(PropertyGroup):
"""Group of properties representing an item in the list."""
name: StringProperty(name="Name")
type: StringProperty(name="Type")
number: FloatProperty(name="min",)
class LIST_OT_NewItem(Operator):
"""Add a new item to the list."""
bl_idname = "my_list.new_item"
bl_label = "Add an item"
def execute(self, context):
item_list=context.scene.my_list
item_value=context.scene.my_list_item
item=item_list.add()
item.name = "Name"
item.type = "Height"
item.number = context.scene.my_list_item
return{'FINISHED'}
class UI_TEST_LIST(UIList):
"""Demo UIList."""
def draw_item(self, context, layout, data, item, icon, active_data, active_propname, index):
custom_icon = None
split = layout.split(factor=0.3)
split.label(text = item.type)
split.label(text = str(item.number))
# Make sure your code supports all 3 layout types
if self.layout_type in {'DEFAULT', 'COMPACT'}:
layout.label(text=item.name)
elif self.layout_type in {'GRID'}:
pass
return
class VIEW3D_PT_ListTestPanel(bpy.types.Panel):
"""Test List Panel"""
bl_label = "List"
bl_idname = "VIEW3D_PT_ListTestPanel"
bl_space_type = 'VIEW_3D'
bl_region_type = 'UI'
bl_category = "List"
def draw(self, context):
layout = self.layout
row = layout.row()
row.template_list("UI_TEST_LIST", "Test List", context.scene, "my_list", context.scene, "my_list_index",rows = 5)
row = layout.row()
row.prop(context.scene,"my_list_item")
row.operator("my_list.new_item",text="Add")
classes = (VIEW3D_PT_ListTestPanel, UI_TEST_LIST, LIST_OT_NewItem, CustomItem)
def register():
for cls in classes:
bpy.utils.register_class(cls)
bpy.types.Scene.my_list = CollectionProperty(type=CustomItem)
bpy.types.Scene.my_list_index = IntProperty(name="my_list_index")
bpy.types.Scene.my_list_item = FloatProperty(name="my_list_item")
def unregister():
for cls in reversed(classes):
bpy.utils.unregister_class(cls)
Even if I just set name to "", the UI List still leaves space for it. I would like the other two properties to fill up the space, horizontally.