Quote Originally Posted by johnny_sparx
What is wrong with the default flags()?
It depends which model you use. If you use a direct subclass of QAbstractItemModel, then it doesn't allow items to be modified. You should make sure it returns ItemIsEditable as part of the flags.

For that matter, shouldn't I be using something like setFlags?
No. The model itself should know whether a particular item is to be editable (or otherwise interactable) and should return proper flags for the item. If you want something like "setFlags", you should somehow set/change the internal state for an item and tell the model to act accordingly upon this. For example you might implement the model in such a way that it won't allow items to be editable if they contain children. It would look more or less like so:
Qt Code:
  1. Qt::ItemFlags MyModel::flags ( const QModelIndex & index ) const {
  2. if(hasChildren(index)){
  3. return Qt::ItemIsEnabled|Qt::ItemIsSelectable;
  4. } else {
  5. return Qt::ItemIsEnabled|Qt::ItemIsSelectable|Qt::ItemIsEditable;
  6. }
  7. return Qt::ItemIsEnabled;
  8. }
To copy to clipboard, switch view to plain text mode 

Allowing a user to directly modify the state of any item could ruin the model.