QVariant TreeModel::data(const QModelIndex &index, int role) const{ if (!index.isValid()) return QVariant(); if (role != Qt::DisplayRole) return QVariant(); TreeItem *item = static_cast<TreeItem*>(index.internalPointer()); return item->data(index.column());}
if (role != Qt::DisplayRole) return QVariant();
if(что-то){ создаем свой editor и возвращаем его}else return QItemDelegate::createEditor(parent, option, index);
QWidget* DelegateEditor::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const{ QString type=static_cast<DataItem*>(index.internalPointer())->data(2).toString(); if(type=="char" || type=="int"){ QList<QVariantMap> Values=static_cast<DataItem*>(index.internalPointer())->getValues(); QSpinBox *editor=new QSpinBox(parent); editor->setMinimum(0); editor->setMaximum(100); editor->installEventFilter(const_cast<DelegateEditor*>(this)); return editor; } else{ return QItemDelegate::createEditor(parent, option, index); }}
QString type=static_cast<DataItem*>(index.internalPointer())->data(2).toString();
index.isValid()
QWidget* DelegateEditor::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const{ return QItemDelegate::createEditor(parent, option, index);}