Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Control.parent property #952

Closed
FeodorFitsner opened this issue Jan 30, 2023 Discussed in #950 · 4 comments · Fixed by #2906
Closed

Control.parent property #952

FeodorFitsner opened this issue Jan 30, 2023 Discussed in #950 · 4 comments · Fixed by #2906
Assignees

Comments

@FeodorFitsner
Copy link
Contributor

Discussed in #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 :)

@iron3oxide
Copy link
Contributor

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.

@ItsCubeTime
Copy link

.parent Yes! This would absolutely help reduce code clutter on my end

@jfabiani
Copy link

.parent Yes that is needed.

@bevzocry
Copy link

+1

@ndonkoHenri ndonkoHenri self-assigned this Mar 18, 2024
@ndonkoHenri ndonkoHenri linked a pull request Mar 18, 2024 that will close this issue
1 task
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

6 participants