[PyQt] QTreeView + sort + delete = crash

Kyle Altendorf sda at fstab.net
Mon May 6 04:50:05 BST 2019


On 2019-05-05 21:52, John F Sturtz wrote:
> [3]
> Regarding passing the view to the model:
> 
> The reason I did this is because, once an item in the tree is edited, I 
> wanted to make it the current item (lines 224-226).  setCurrentIndex() 
> is a view-level method, so I needed a reference to the view to invoke 
> it (or thought I did).  I've bumped into this several times, and always 
> 'solved' it this way (though I never did _quite_ feel like it was the 
> right thing to do).
> 
> What would be considered the 'right' way to handle this?  Should I be 
> connecting a signal to the setCurrentIndex() slot and emitting that?

Maybe dataChanged()?  I don't do this and didn't test it though.

https://doc.qt.io/qt-5/qabstractitemview.html#dataChanged

If not that then at least use a signal/slot, yeah.  The signal/slot 
option would make it more controllable independent of existing semantics 
around dataChanged(), is naturally expandable to multiple views or 
optional per view, etc.

Cheers,
-kyle


More information about the PyQt mailing list