[PySide] [Maya 2014] Refreshing a Tree View in Qt

I am using a QAbstractItemModel and QTreeView to display a hierarchy of joints. I want to clear and re-populate the TreeView when my selection changes.

Based on the Qt Documentation, I need to re-implement the removeRows method for the QAbstractItemModel and I have done that based on Yasin’s tutorials.

When I try to clear the TreeView and re-populate it with new data, removeRows returns False, and I just end up appending the new data to the TreeView.

Most of the answers I’ve found on StackOverflow and elsewhere indicate that re-implementing removeRows should work, but I haven’t had any luck yet.

What else could I be overlooking?
Thanks.

[EDIT: NVM, found my problem, a syntax error as a result of copying and pasting code around…]

just out of curiosity, why did you choose to go the QAbstractItemModel route vs QStandardItemModel?

no reason actually, I was just following some examples. I am not doing anything out of the ordinary, the StandardItemModel would probably save me a lot of hassle.

Hey rgkovach123, it sounds like you might be looking to reset the model as opposed to removing each row by hand. The benefit is two-fold, firstly each time you remove a row you trigger and update in the view. Qt deduplicates tightly followed similar events so the penalty isn’t as large as could be, but it is still there. Secondly, a model reset is much easier.