I'm currently working on a customization of QAbstractItemModel
an I encountered a problem. The model itself works fine so far, but I have problems, if i try to display it with QTreeView.
The Model itself is able to change its column number on its own, depending on it's data. But the view will never update the number of columns shown, only their content.
I did overload insertColumns
:
bool MyModel::insertColumns(int column, int count, const QModelIndex &parent)
{
bool success;
beginInsertColumns(parent, column, column + count - 1);
success = this->getItem(parent)->insertColumns(column, count);
endInsertColumns();
return success;
}
I experimented a little bit and found out, that if I reset and set the View each time, it will display the right number of columns:
connect(this->model, SIGNAL(columnsChanged()), this->ui->treeView, SLOT(reset()));
But there has to be another way to do this. I'm looking for a function, that will just tell the View that the column-count has changed. But the only one i found (QTreeView::columnCountChanged(int oldCount, int newCount)
) is protected...