我定义了一个treeview,当使用标准model,即 QStandardItemModel model(4, 4); 的时候,可以delegate 一些控件,但是当我使用其他一些model时,比如Foundations_of_Qt_Development这本书的一个例子中的model,就无法delegate 空件了。请问这是为什么?谢谢!!
这是那个例子中定义的model
class ObjectTreeModel : public QAbstractItemModel
{
public:
ObjectTreeModel( QObject *root, QObject *parent = 0 );
Qt::ItemFlags flags( const QModelIndex &index ) const;
QVariant data( const QModelIndex &index, int role ) const;
QVariant headerData( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const;
int rowCount( const QModelIndex &parent = QModelIndex() ) const;
int columnCount( const QModelIndex &parent = QModelIndex() ) const;
QModelIndex index( int row, int column, const QModelIndex &parent = QModelIndex() ) const;
QModelIndex parent( const QModelIndex &index ) const;
private:
QObject *m_root;
};
delegate 的代码是参照examples\itemviews\spinboxdelegate中的,我就不贴上来了