I have a QTreeWidgetItem
with two columns of data, is there any way to make only the second column editable? When I do the following:
QTreeWidge
Seem like the standard QTreeWidget doesn't allow this. I think there are two ways to do this:
Use a QTreeView with your own class derived from QAbstractItemModel and override the flags function
Use a QTreeView with a QStandardItemModel. Then when you add the item just set the appropriate column to allow edits:
Here's some code for the second option:
QString x, y;
QList newIt;
QStandardItem * item = new QStandardItem(x);
item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsUserCheckable | Qt::ItemIsEnabled | Qt::ItemIsDragEnabled);
newIt.append(item);
item = new QStandardItem(y);
item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsUserCheckable | Qt::ItemIsEnabled | Qt::ItemIsDragEnabled | Qt::ItemIsEditable);
newIt.append(item);
model->appendRow(newIt);
I find the second approach simpler but that depends on how much flexibility you want with your model.