I have implemented my QTreeView & QAbstractItemModel according to editabletreemodel example plus the advice here: QTreeView & QAbstractItemModel & insertRow.
It works, ok. But there is a difference I do not understand.
To make my application work properly when inserting child rows I had to emit layoutChanged(). I had to. If I don't emit - inserting a child works not good: a new child correctly appears in model, it is correctly saved (when I save), but it is NOT shown in view.
The editabletreemodel example does not contain "emit layoutChanged()", and it works fine with inserting children.
Here is my insertRows method of QAbstractItemModel sibling class:
bool ExTree::insertRows(int position, int rows, const QModelIndex &parent)
{
ExObject *parentItem = getItem(parent);
bool success;
beginInsertRows(parent, position, position + rows - 1);
success = parentItem->insertChildren(position, rows, rootItem->columnCount());
endInsertRows();
if(success) emit layoutChanged();
return success;
}
It is almost like those in editabletreeview example, the only difference is the emit.
Why, please?
I want to understand, WHY exactly I needed to emit layoutChanged(), while editabletreeview does not do this. Will appreciate greatly if anyone can explain this point.
I do not need understanding why emit. I need understanging why I need to emit and editabletreeview does not need it.