[PyQt] QTreeView + sort + delete = crash
John F Sturtz
john at sturtz.org
Thu May 9 05:06:56 BST 2019
On 5/7/2019 12:21:24 PM, Kyle Altendorf <sda at fstab.net> wrote:
Is this really all you do when you sort?
# Sort children
def sort_children(self):
self.children.sort(key=lambda x: x.desc())
return
Yes, that would upset Qt very much. You would need to do a series of
moves or a restructure or... I'm forgetting the terms offhand. But
yes, you have to tell Qt when stuff moves around. This would be part of
why it's useful to let an entirely stock Qt object like a proxy take
care of it for you.
Cheers,
-kyle
Problem solved, I think (haven't seen any issues or crashes in testing so far).
It seems you were right, Kyle -- a proxy was the way to go. It took me some mucking around to eventually grok QSortFilterProxyModel well enough to hook it into my app. Once I did, that seems to do the trick.
Thanks again for all the help Kyle and Florian! Learning all the time ...
The modified file that seems to work is attached, in case anyone else was following.
/John
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20190508/4d58eb7b/attachment-0001.html>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: cat.py
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20190508/4d58eb7b/attachment-0001.ksh>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: dlg.ui
Type: text/xml
Size: 4323 bytes
Desc: not available
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20190508/4d58eb7b/attachment-0001.xml>
More information about the PyQt
mailing list