I am trying to use a selection (QModelIndexList) to check all the selected items of a QTreeView.
I use setData with the Qt::CheckStateRole on the indexes and the data seems updated.
I am emitting dataChanged signal but the tree is not redrawn (with and without the role given as argument).
Is this an issue of the selection model?
It works if I do beginResetModel but my tree gets collapsed which a deal breaker.
How can I manage to get my item repainted?
Here is the method I added in my model
void MyModel::checkSelectedItems( const QModelIndexList &checkedIndexes, bool check )
{
QVector<int> roles = QVector<int>() << Qt::CheckStateRole;
for ( const QModelIndex &index : checkedIndexes)
{
setData(index, check ? Qt::Checked : Qt::Unchecked, Qt::CheckStateRole);
emit dataChanged(index, index); //), roles);
}
}
and the call to it:
myModel->checkSelectedItems( myTree->selectionModel()->selectedIndexes(), true );
After the call, the selection is grey (and not blue anymore) but still "selected". Clicking anywhere refresh the tree and correctly shows the checked items.
myModel->checkSelectedItems( myTree->selectionModel()->selectedIndexes(), true );writemyTree->update();. - scopchanovmyTree->update(index)with the modified index. - Denis RouzaudmyTree->repaint()solved the issue, but I am not sure this is the correct approach. - Denis Rouzaud