-
-
Notifications
You must be signed in to change notification settings - Fork 791
[Qt] Tree Widget #4112
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
base: main
Are you sure you want to change the base?
[Qt] Tree Widget #4112
Conversation
freakboy3742
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code looks good; however, in manual testing of the tree example (in a VM running Ubuntuu 24.0.3), I'm getting a segfault when I try to remove a row. Not sure why that isn't manifesting during the testbed, though.
I can replicate on KDE (it doesn't happen when running Qt on macOS for whatever reason). Also not sure why it's not happening in the tests, but it may be because Qt is trying to re-draw or size the widget during the remove operation. I have a reasonable idea of what's going on:
So the solutions I can see right now are:
Of these, 1 is simple; 2 is "right"; 3 is performant; and 4 is generalised. One note on #4028 is that I was working under the assumption that Qt never did anything while we are running pure Python code; that assumption appears to be false. |
|
The simple fix doesn't work. The attempted fix also doesn't work the problem, but it does delay the segfault until after the |
If there's any sort of independent/threaded redraw mechanism, this seems entirely plausible - the precise timing of a redraw being triggered won't always coincide with the Toga-side row removal. This also potentially explains why it doesn't trigger in CI, because CI has very little "breathing room" for background cycles, and the high-churn environment means garbage collection isn't really representative of "real world" usage.
My initial impression is that 3 would be an acceptable fix here. This is a good example where we have a native representation referencing a canonical object, where the lifecycles of the two won't necessarily align, and deletion of the canonical object shouldn't be blocked on a reference from the native layer. |
There's something more going wrong here: I put in some non-weak caching and some instrumentation and I can see that the selection is holding stale In any case, I've added an extra sub-test to the row-change sub-test that removes the currently selected row and which replicates the segfault (and on macOS Qt as well, where it wasn't happening).
|
…tion." This reverts commit 855e280.
|
@freakboy3742 This is ready for a re-review, but may need a re-design if behaviour is not acceptable. Compared to the last review, this iteration now completely resets the model on inserts and deletes, which guarantees that all There is a core problem that when we get Fundamentally, there are two approaches to solving this:
|
freakboy3742
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Confirming that this resolves the crash issue; but my inclination is that the "reset" behavior on any insertion or deletion is going to be surprising.
The performance implications of using the built-in model seems like a regression when we know there's a better option available; so moving to pre-insert/remove notifications seems like the way forward to me.
That said - this works - I'm happy to land this as-is and treat adding pre notifications as a follow up; or if you think we can get pre-notifications in place in this PR without too much effort, I'm happy to do that as well. Let me know which approach you'd prefer.
Implement the Qt Tree widget.
Fairly straightforward other than the complexities of the
QAbstractItemModelfor a tree. We store references to node objects on theQModelIndexobjects to avoid having to walk up and down the tree constantly.For the widget warning check, Qt doesn't know whether a cell contains a widget or not until it is actually visible, so the warning gets issued on expanding the rows, not on display of the table and we needed to adjust the tests slightly to accomodate this.
Like the Table, we have with evenly-spaced non-changable column widths for now (see #4109).
Includes a fix of #4111 since I needed that for manual testing. It also includes a fix to a couple of fixtures which should have been async.
Ref #3914.
Fixes #4111.
To Do:
PR Checklist: