I have an UIList in which I display a PropertyGroup defined like this:
class CUSTOM_PG_library_list(bpy.types.PropertyGroup):
lib_name: bpy.props.StringProperty(name ="lib_name")
lib_last_mod: bpy.props.IntProperty(name ="lib_last_mod")
lib_active: bpy.props.BoolProperty(name="lib_active", default=False)
class CUSTOM_UL_items(UIList):
def draw_item(self, context, layout, data, item, icon, active_data, active_propname, index):
checkbox = "CHECKBOX_HLT" if item.lib_active else "CHECKBOX_DEHLT"
split = layout.split(factor=0.1)
split.prop(item, "lib_active", text="", emboss=False, icon=checkbox)
split.label(text=item.lib_name)
I never worked with UILists so I have a bit of a hard time to understand how they work.
In the UiList, I would like to be able to only set one checkmark at any time. (Switching the others off). Unfortunately, toggling the checkmark on or off is a different action as selecting one line in the UIList.
Is it possible to bind the click on an UIList line (name or checkmark doesn't matter) together? So if I click on a line it toggles the checkmark belonging to that line to on but also turns all other off. (One needs to be selected, so there can not be a state where all are off.)
How can I achieve this? Do I need an update function to lib_active or some sort of an update function to the UIList itself?
EDIT: Here is the call from the UI:
layout.template_list("CUSTOM_UL_items", "", self, "lib_list", self, "lib_list_index", rows=2)
The look should be like this:
What I would like to avoid is this:
(UIList selection and Set Checkmark are mismatched.)
I don't know how to "synchronize" the click on a list with the state of a checkmark. For example, I can toggle the checkmark without selecting the list, which is also not what I want. Checkmark and active line in UIList should be always the same.
data.active_propname
value is changed when you click on a UI list element. Where do you store it ? How do you call the ui list template in your layout code ? $\endgroup$