If the flag function returns a value including Qt::ItemIsUserCheckable, Qt calls the setData function with a value that is the opposite of the one currently displayed by the checkbox.
So if it's checked it will call setData with the Qt::Unchecked value?
setData(const QModelIndex& index, const QVariant& value, int role)
setData(const QModelIndex& index, const QVariant& value, int role)
To copy to clipboard, switch view to plain text mode
Trough which : "QVariant& value" or "int role" ?
The setData function now must emit dataChanged and return true; it must also do “something†that will tell the data function to return the opposite value from the one it returned before for this index.
So:
setData(const QModelIndex& index, const QVariant& value, int role) {
if (role == Qt::CheckStateRole) {
///////*
If the checkbox is checked, tell data() to uncheck it;
If unchecked, tell data() to check it;
*////////
emit dataChanged(index, index);
return true;
}
return QFileSystemModel::setData(index, value, role);
}
setData(const QModelIndex& index, const QVariant& value, int role) {
if (role == Qt::CheckStateRole) {
///////*
If the checkbox is checked, tell data() to uncheck it;
If unchecked, tell data() to check it;
*////////
emit dataChanged(index, index);
return true;
}
return QFileSystemModel::setData(index, value, role);
}
To copy to clipboard, switch view to plain text mode
The value should change between checked and unchecked... if you’ve implemented data correctly.
The value should change between checked and unchecked... if you’ve implemented data correctly.
To copy to clipboard, switch view to plain text mode
You mean QVariant& value?
Bookmarks