-1

In a QTreeView if the user was editing previousIndex and hit TAB an editor is opened for currentIndex, the default behaviour is to open a blank textedit so that if the user immediately hits TAB again the cursor moves to nextIndex and the model received a setData(currentIndex, QVariant() ) with an empty QVariant as data.

Is it possible to alter this behaviour so that by hitting TAB the user opens an editor but the already existing data remains there, so that the user needs to explicitly delete it?

I imagine that I can accomplish this by using

void QAbstractItemDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const

But I'm not sure where to put the call to it.

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
Reimundo Heluani
  • 918
  • 9
  • 18

1 Answers1

1

I was just battling a similar issue, where editing a cell in a qtreeview was clearing the cell, instead of highlighting the current text.

I found your question while trying to find the answer, so maybe my experience will be useful.

My problem was in my model::data() method.

I had an early exit test:

if (role != Qt::DisplayRole) 
    return QVariant();

This was working as designed - as soon as I entered edit mode, it was returning an empty value.

I added EditRole to the test and it worked correctly.

if (role != Qt::DisplayRole && role != Qt::EditRole) 
    return QVariant();
David
  • 41
  • 6