Checkableproxymodel - programmatically uncheck a node
-
I am using Checkableproxymodel example by Andres. I need to check/uncheck files and directories based on a list. I cannot seem to programmatically uncheck a file node using the following:
@
QDirIterator it(...);
while (it.hasNext())
{
it.next();if(ignoredDir.contains(it.filePath().remove(getTestDir() + "/"), Qt::CaseSensitive)) { QModelIndex idx = fsModel->index(it.filePath(), CheckableProxyModel::COL_FILE_NAME); m_checkProxy->setData(m_checkProxy->mapFromSource(idx), false, Qt::CheckStateRole); continue; } else { if (ignoredTest.contains(it.fileName(), Qt::CaseSensitive)) { qDebug() << "Unchecking " << it.fileInfo().filePath(); QModelIndex idx = fsModel->index(it.fileInfo().filePath(), CheckableProxyModel::COL_FILE_NAME); fileTree->setExpanded(m_checkProxy->mapFromSource(idx), true); fileTree->setCurrentIndex(m_checkProxy->mapFromSource(idx)); m_checkProxy->setData(m_checkProxy->mapFromSource(idx), false, Qt::CheckStateRole); return; } } }
@
I can highlight the specific file node using the above but unchecking (line 20), actually unchecks the parent directory instead of the specific file node. Please help.
-
Why don't you use the methods provided for that: setSourceIndexCheckedState() and setCheckedState().
-
thanks Andre!