Note that there are some explanatory texts on larger screens.

plurals
  1. POqlistview with checkboxes using custom model
    primarykey
    data
    text
    <p>I have subclassed filesystemmodel to include checkboxes in listview , which is working fine. My problem is whenever I click an item the text of that item disappears and when i click another item the text of previously selected item becomes visible. Can anyone please tell me the reason behind it.</p> <p>Here is the code i implemented.</p> <p>Please tell me what i am missing here, Thanks</p> <pre><code>#include "custommodel.h" #include &lt;iostream&gt; using namespace std; CustomModel::CustomModel() { } QVariant CustomModel::data(const QModelIndex&amp; index, int role) const { QModelIndex parent=this-&gt;parent(index); if(role == Qt::DecorationRole) { if(this-&gt;filePath(parent)=="") { return QIcon(":/Icons/HardDisk.png"); } else if(this-&gt;isDir(index)) { QDir dir(this-&gt;filePath(index)); QFileInfoList files = dir.entryInfoList(QDir::NoDotAndDotDot | QDir::Files | QDir::Dirs); for(int file = 0; file &lt; files.count(); file++) if(files.count()&gt;0) return QIcon(":/Icons/FullFolder.png"); if(files.count()==0) return QIcon(":/Icons/EmptyFolder.png"); } else{ QFileInfo fi( this-&gt;filePath(index)); QString ext = fi.suffix(); if(ext=="jpeg"||ext=="jpg"||ext=="png"||ext=="bmp") return QIcon(filePath(index)); } } if (role == Qt::CheckStateRole &amp;&amp; !(this-&gt;filePath(parent)=="")) return checklist.contains(index) ? Qt::Checked : Qt::Unchecked; return QFileSystemModel::data(index, role); } Qt::ItemFlags CustomModel::flags(const QModelIndex&amp; index) const { return QFileSystemModel::flags(index)| Qt::ItemIsUserCheckable; } bool CustomModel::setData(const QModelIndex&amp; index, const QVariant&amp; value, int role) { if (role == Qt::CheckStateRole) { if (value == Qt::Checked) checklist.insert(index); else checklist.remove(index); emit dataChanged(index, index); return true; } return QFileSystemModel::setData(index, value, role); } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload