1
votes

when reimplement QAbstractItemModel::setData ( const QModelIndex & index, const QVariant & value, int role = Qt::EditRole ) as for the roles that we want to ignore ,what should we do ? return false or return true ?or anything else ?

examples in the Qt documentation are even self-contradictory here the return value is false http://qt-project.org/doc/qt-4.8/model-view-programming.html#making-the-model-editable but here the return value is true http://qt-project.org/doc/qt-4.8/modelview.html#2-5-the-minimal-editing-example

1

1 Answers

1
votes

You can return false if you consider that is an error to set data for this role and you want to avoid that.

You can return true if you want to ignore this data role but it isn't critical to try (but you should print an warning).

In this way, you don't "break" the setData() behavior (false: there is something wrong, true: it's OK, you can continue).

You should not return anything else to avoid weird behavior because user will wait a boolean. For example, if you test the return value that should be a boolean:

if setData( "test", Qt.DisplayRole) == False:
   foo()
else:
   bar()

bar() will be called even if setData() doesn't return True.