Hi!
I have a QTreeview which displays a FilesystemModel with Checkboxes before the files. If a directory gets checked and has childs, all the subitems should get checked.
The logic is working BUT the view does not get refreshed!
If I have the directory with sub-items expanded I have to collapse/expand it again to see the (correct) rendered result.
The code in question is this:
{
if(index.isValid() && index.column() == 0 && role == Qt::CheckStateRole) {
const QString path
= this
->filePath
(index
);
if(m_files.isEmpty()) {
return Qt::Unchecked;
}
if(m_files.contains(path)) {
return Qt::Checked;
}
if(m_excludeFiles.contains(path)) {
return Qt::Unchecked;
}
if(parentIsExcluded(path)) {
return Qt::Unchecked;
}
if(parentIsChecked(path)){
return Qt::Checked;
}
return Qt::Unchecked;
}
return QFileSystemModel::data(index, role);
}
QVariant FileModel::data(const QModelIndex &index, int role) const
{
if(index.isValid() && index.column() == 0 && role == Qt::CheckStateRole) {
const QString path = this->filePath(index);
if(m_files.isEmpty()) {
return Qt::Unchecked;
}
if(m_files.contains(path)) {
return Qt::Checked;
}
if(m_excludeFiles.contains(path)) {
return Qt::Unchecked;
}
if(parentIsExcluded(path)) {
return Qt::Unchecked;
}
if(parentIsChecked(path)){
return Qt::Checked;
}
return Qt::Unchecked;
}
return QFileSystemModel::data(index, role);
}
To copy to clipboard, switch view to plain text mode
The flags method returns
defaultFlags |= Qt::ItemIsUserCheckable;
defaultFlags |= Qt::ItemIsUserCheckable;
To copy to clipboard, switch view to plain text mode
setData just fills my QSets (m_files, m_excludeFiles) and returns true or calls QFileSystemModel::setData(index, value, role);
What am I missing?
Thank you very much
m.
Bookmarks