title: how set QCheckBox in QAbstractItemModel?
body: <p>I have a model</p>
  
  <pre><code>class TreeModel : public QAbstractItemModel
  </code></pre>
  
  <p>which I populate with instances of my <code>TreeItem</code> excluding <strong>column==1</strong>. In <strong>column 1</strong> I've created <code>CheckBoxes</code>:</p>
  
  <pre><code>QVariant TreeModel::data(const QModelIndex &amp;index, int role) const {
      if (!index.isValid())
          return QVariant();
  
      if (role != Qt::DisplayRole) {
          if (role == Qt::CheckStateRole) {
              if (index.column() == 1) {
                  if (index.row() == 1) {
                      return Qt::Unchecked;
                  } else
                      return Qt::Checked;
              }
          }
          return QVariant();
      }
      if (role == Qt::DisplayRole) {
          if (index.column() != 1) {
              TreeItem *item = static_cast&lt;TreeItem*&gt;(index.internalPointer());
              return item-&gt;data(index.column());
          }
      }
      return QVariant();
    }
  </code></pre>
  
  <p>I can set these CheckBoxes statues to <code>Qt::Checked</code> or <code>Qt::Unchecked</code> but my problem is:
  <strong>I cannot change them later when they are clicked</strong> (however <code>setData</code> is called with appropriate <code>index.column==1</code> and <code>role==Qt::CheckStateRole</code>). 
  I have seen examples with <code>ItemDelegate</code> - only this seems to work. Is this true? Do I have to use delegate in this scenario?</p>
  
  <p>Here is my <code>setData()</code> function: </p>
  
  <pre><code>bool TreeModel::setData(const QModelIndex &amp; index, const QVariant &amp; value,
          int role) {
      if (role==Qt::CheckStateRole &amp;&amp; index.column() == 1) {
          TreeItem *item = static_cast&lt;TreeItem*&gt;(index.internalPointer());
          QTreeWidgetItem *check = static_cast&lt;QTreeWidgetItem*&gt;(index.internalPointer());
  
          //if (item-&gt;data(index.column()) == Qt::Checked)
          if (value == Qt::Checked){
              int i=1;
              //check-&gt;setCheckState(1,Qt::Checked); //SIGSEGV
          }else{
              //(item-&gt;data(index.column())) = Qt::Unchecked;
              int i=2;
              //check-&gt;setCheckState(1,Qt::Unchecked);
          }
  
          emit dataChanged(index, index);
          return true;
      }
      emit dataChanged(index, index);
      return true;;
  }
  
  
  Qt::ItemFlags TreeModel::flags(const QModelIndex &amp;index) const {
      if (!index.isValid())
          return 0;
  
      return Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsUserCheckable |  Qt::ItemIsEditable;
    }
  </code></pre>