[Qt-interest] Custom delegate only for certain items
RZ
rz at razfazz.at
Fri Jun 12 00:10:17 CEST 2009
Arnold Krille schrieb:
> On Thursday 11 June 2009 23:20:35 RZ wrote:
>> My QTreeView got 2 columns, many rows - items in the second column are
>> not editable for the user. Items in column 0 are editable - but only
>> items in the third hierarchy level shall use the custom delegate.
>> If i got everything correctly each block of items is on the same row (so
>> setItemDelegateForRow won't help) and they are in the same column (so
>> setItemdelegateForColumn doesn't help).
>> Has someone got an idea how to solve that?
>
> Maybe you have to derive your delegate from the standard delegates and decide
> wether to use your own delegate on the modelindex given. Third level means the
> grandparents parent is invalid. ;-)
>
> Arnold
That was the same thought after I had typed and sent the message.
Sometimes it helps to explain your problem ;-)
Anyway it would mean returning a QLineEdit in my createEditor function
and also adding some lines of code in e.g. setEditorData like:
if (qobject_cast<QLineEdit*>)
{
model->setData(index, editor->text(), Qt::EditRole);
}
else if (qobject_cast<QComboBox*>)
{
model->setData(index, editor->currentText(), Qt::EditRole);
}
which is not of extreme elegance I think (but might be the best solution
though).
More information about the Qt-interest-old
mailing list