I created a list view and shown it on MainWindow widget.
The UI of a single element is designed in UITemplate widget.
The data of a single element comes from Data widget.
Each element in the list view has a checkbox. How can I keep track of checked elements in MainWindow widget?
Method I tried:
Tried event dispatchers, but when I try to bind an event for that, it asks for a UITemplate object reference. I was in MainWindow widget, and created Data widget instances to be added to the list view. Couldnât get a UITemplate reference.
You can do the bind when you spawn the instances, each instance can have an id also created when you instantiate them, or simply add them to a list and use their index
When I add entries to list view, should I add data widget or UI widget? From many tutorials, they spawn data instances then in the UI widget on On List Item Object Set, they cast the List item object to Data class. If to do so, I wonât have any reference to the UI widget itself, so when binding the event, there is no value for âTargetâ. Question seems dumb, I am sorry!
This script would live in the widget that hosts the listview itself but you can also delegate the dispatch to another actor / widget. Ensure you flag both the List View and the Checkbox (in the instantiated widget as isVariable at the very top of the details panel)
Thanks I got the on check state change event working! But I am confused that in your BP, you get the checkbox 19 from New Widget Blueprint, then assign it to the target of âBind Event to On Check State Changedâ. I canât do the same since the âtargetâ requires widget, not checkbox.
I canât do the same since the âtargetâ requires widget, not checkbox.
This is not true; a native (as above) OnCheckStateChanged requires a checkbox â thatâs precisely what you asked about in the topic. Perhaps thereâs some confusion regarding how list view works:
there is a user widget with a checkbox
there is a list view that creates those user widgets by pulling data from objects
when the list view instantiates the User Widget with a Checkbox, we get its checkbox and bind its delegate
If in doubt, post script. Without knowing the details of the setup, itâs hard to imagine whatâs going on on your end.
Youâre right. OnCheckStateChanged does require a checkbox as target. I was confused with another eventâs similar name.
Now I want to know which element called the event, as the graph shown, tries to print the name of the element containing the checkbox. But I always get the last elementâs name. Is there a way to get a reference to the widget thatâs calling OnCheckStateChanged? Ultimately I just wanna keep an array of checked and unchecked elements.
inside the TileUITemplate, add an Event Dispatcher with any data signature that you need
still inside the TileUITemplate, have the onCheckStateChanged call the dispatcher you added, pipe in the state of the checkbox and any other data (you could even send a Self reference - but it seems you want a string)
when binding (as in your screenshot above) rather than binding to the native onCheckStateChanged, bind the event to TileUITemplate directly