Reputation: 6193
I already have a QTreeView with an own model and a delegate that is able to show a QComboBox in one column of this QTreeView.
Now dependent on the data shown in the tree, the QComboBox has to be enabled and activated only for some of the cells, not for the complete column. I already found that no QComboBox is shown and handled when the delegate's function createEditor() returns NULL. But: createEditor() does not come with a reference to the model, so I can not ask it for the given index if the QCombobox has to be shown or not. On the other hand I can not store the related information in the delegate (because it is a generic one and such a solution would violate the separation beween view and data IMHO).
So: how can I access the model out of createEditor() or what other possibilities do I have to hide a delegated QComboBox dynamically for some cells of my QTreeView?
Thanks!
Upvotes: 0
Views: 252
Reputation: 2602
You can get the model from the QModelIndex
QWidget * createEditor(QWidget * parent, const QStyleOptionViewItem & option, const QModelIndex & index) const
{
const QAbstractItemModel * model = index.model();
//.....
}
So you have both the index and the model, and I think is enough to determine if create a combo box or not.
From the question is not clear if the others cells must be editable by another widget. If it is not the case, you can simply make the cells not editable returning the correct flags in your model (include Qt::ItemIsEditable
only for the editable cells.) See QAbstractItemModel::flags
Upvotes: 3