The simplest way that I found was to use Qt::ItemFlags
void myClass::treeDoubleClickSlot(QTreeWidgetItem *item, int column)
{
Qt::ItemFlags tmp = item->flags();
if (isEditable(item, column)) {
item->setFlags(tmp | Qt::ItemIsEditable);
} else if (tmp & Qt::ItemIsEditable) {
item->setFlags(tmp ^ Qt::ItemIsEditable);
}
}
The top of the if
adds the editing functionality through an OR
, and the bottom checks if it is there with AND
, then removes it with a XOR
.
This way the editing functionality is added when you want it, and removed when you don't.
Then connect this function to the tree widget's itemDoubleClicked()
signal, and write your 'to edit or not to edit' decision inside of isEditable()