首先我先继承代理类
class SNodeInfoDelegate : public QItemDelegate
{
public:
SNodeInfoDelegate(QObject *parent);
QWidget* createEditor(QWidget *parent, const QStyleOptionViewItem &option,
const QModelIndex &index) const;
void setEditorData(QWidget *editor, const QModelIndex &index) const;
void setModelData(QWidget *editor, QAbstractItemModel *model,
const QModelIndex &index) const;
void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option,
const QModelIndex &index) const;
};
如此我已经可以实现在QTableView上显示控件,只是每次需要判断一下index.row()和column(),然后处理,但是这个方法档数据量很大时程序变得很不好读,而且也不灵活,特别是绑定多个model/view的时候没法处理
不知有没有方法可以根据来源数据进行处理,我的第一个想法是重载QModelIndex然后绑定数据,但发现model和view的诸多类都要重写,有没有其他的解决方案