Qt: QStandardItem.insertRow vs QStandardItemModel.insertRow

Hi,

I’m trying to make a ui for a tree data structure, using subclassed QStandardItemModel and QStandardItem objects.

It seems to manipulate the rows of the model, one can call insertRows() on either the model or the parent item itself - however, when calling it on the model, you also need to call beginInsertRows() and endInsertRows(), whereas on the item, you don’t? Also it seems like calling it directly on the items does not properly update the connected view widget. I’m using PySide2, though I hope that doesn’t matter.

I’m very confused as to why there are two entrypoints which apparently do the same thing, but have different requirements and outcomes.

Any help is greatly appreciated,
Thanks

i would definitely use the model, the model should be connected to a view (qtreeview, qtableview, whatever). Updating the data in the model will automatically update the view. Yes, in your case you need to call begin and end functions, but i think it is easier than having to essentially write your own functions if you want to update the item itself.

QStandardItemModel is like a collection of QStandardItems, you can let the model handle all the updates, structuring and sorting or you can do that yourself, but then it would seem you are just rewriting the code that is already there. Wouldn’t do that unless there is something very specific you are trying to implement.