PDA

View Full Version : How to clear QTreeView derived from QAbstractItemModel



chithara
24th October 2018, 10:46
Hi,

I am using a QTreeview whose model class is derived from QAbstractItemModel. I have my model data in a QList, to populate the treeview. Now, on click of Cancel button, i want to clear all the items in the treeview (make it empty). QTreeview is not getting cleared just by clearing the QList model data.Not sure, how to use beginresetmodel,endresetmodel,etc . Please help me on this

d_stranz
25th October 2018, 23:13
In your custom model, in whatever method it is that you clear the QList, call beginResetModel() -before- you clear the list, then endResetModel() -after- you have cleared it. The tree view should automatically update itself once the method exits and control returns to the event loop.