ItemList signals in multi-select mode don't make sense

Godot Version

v4.2.1.stable.official [b09f793f5], linux

Question

I’m confused by the item_selected and multi_selected signals when an ItemList is in multi-select mode.

ItemList can emit two signals to describe items being selected, item_selected and multi_selected. item_selected just passes the index of the selected item, and is only used when the selection mode is set to ‘single’. multi_selected passed the index of the selected item and a bool to indicate whether the item was just added or removed from the selection. When ItemList is in multi-select mode it only emits multi_select signals and never the other.`

This leads to the problem that I can’t externally keep track of which items are selected (e.g. if I want to do some logic based on the selected items as they’re selected/deselected). Without an item_selected signal being emitted to distinguish between starting a new selection with a single click compared to adding an item with a shift/ctrl-click, I can’t know whether the selection has been reset or not.

Is this a bug? Should item_selected still be emitted if a single item is clicked/selected? Or if this intended behaviour and I’m missing something?

you can use get_selected_items to have all you need in your signal handler

1 Like

Thanks, that works as I can check the selected items array against the external list. It just feels a bit less clean since shift-selecting three items will trigger three signals, and get_selected_items will be [0], [0, 1], [1, 2, 3] on each signal. That’s not a big problem really. Thanks for the suggestion!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.