Odin07
25th June 2020, 08:11
Hello,
i have a problem updating my view (QAbtractItemView) when i change the root item in the model (QAbtractItemModel).
My data forms a tree with some branches serving as RootItems in the model. If I now change the RootItem, the view is not updated. Only if the value of a parameter changes and it emits a signal, that parameter is updated in the view.
If the RootItem changes, I call dataChanged(), which does nothing. I have also called resetInternalData(), which doesn't help either.
13483
Here is my method where I change the RootItem.
void TileContentBaseModel::setRootItem(BaseItem * rootItem)
{
if (RootItem != rootItem)
{
beginResetModel();
if (RootItem)
{
disconnect(RootItem, SIGNAL(changedValue(BaseItem*)), this, SLOT(updateValue(BaseItem*)));
}
RootItem = rootItem;
if (RootItem)
{
connect(RootItem, SIGNAL(changedValue(BaseItem*)), this, SLOT(updateValue(BaseItem*)));
}
endResetModel();
QModelIndex index1 = index(0,0, QModelIndex());
QModelIndex index2 = index(rowCount()-1,columnCount()-1, QModelIndex());
emit dataChanged(index1,
index2,
QVector<int>()
<< Qt::DisplayRole
<< Qt::TextColorRole);
}
}
I am grateful for any advice.
i have a problem updating my view (QAbtractItemView) when i change the root item in the model (QAbtractItemModel).
My data forms a tree with some branches serving as RootItems in the model. If I now change the RootItem, the view is not updated. Only if the value of a parameter changes and it emits a signal, that parameter is updated in the view.
If the RootItem changes, I call dataChanged(), which does nothing. I have also called resetInternalData(), which doesn't help either.
13483
Here is my method where I change the RootItem.
void TileContentBaseModel::setRootItem(BaseItem * rootItem)
{
if (RootItem != rootItem)
{
beginResetModel();
if (RootItem)
{
disconnect(RootItem, SIGNAL(changedValue(BaseItem*)), this, SLOT(updateValue(BaseItem*)));
}
RootItem = rootItem;
if (RootItem)
{
connect(RootItem, SIGNAL(changedValue(BaseItem*)), this, SLOT(updateValue(BaseItem*)));
}
endResetModel();
QModelIndex index1 = index(0,0, QModelIndex());
QModelIndex index2 = index(rowCount()-1,columnCount()-1, QModelIndex());
emit dataChanged(index1,
index2,
QVector<int>()
<< Qt::DisplayRole
<< Qt::TextColorRole);
}
}
I am grateful for any advice.