`Control.parent` property
Discussed in https://github.com/flet-dev/flet/discussions/950
Originally posted by ndonkoHenri January 29, 2023
@FeodorFitsner, what do you think of adding a way to access the parent of a control?
I thought of this idea because alot of guys have been asking how to delete an item from a ListView (ListTile) when a button/Control in the tile is pressed.
The way I solve this issue was to always add a reference to the tile in the data property of the Control which will be used to delete the tile... and when the required event happens, grab the e.control.data(the ref), and remove it from the ListView.controls list. Nevertheless, I think a better, efficient, and alternative approach could be to access the parent of that Control e.control.parent(the ref), and remove it from the ListView.controls list.
Why could this be useful?
Using references could become an issue or fail when the Control keeping that reference is moved elsewhere. Whereas, using the .parent is cleaner and will never fail, because when the Control we need is moved any where, it's .parent is changed to its new parent.
I maybe poorly explained my thoughts, but .parent could be used in many other areas.
Let me know what you think of this. I just had the idea, but don't even know if it will be possible to implement :)
Maybe it would make sense to add some functionality regarding children too while we're at it? In Qt there's a children list and findChild() as well as findChildren() methods for every QObject.
This would be useful for use cases like the one mentioned above when e.g. only some child controls fulfilling a certain condition should be removed from a list.
.parent Yes! This would absolutely help reduce code clutter on my end
.parent Yes that is needed.
+1