QStandardItemModel 常用api
QStandardItemModel model;
增:
添加列:
第一种方法:
void setHorizontalHeaderLabels(const QStringList &labels)
第二种方法:
void appendColumn(const QList<QStandardItem *> &items)
添加行:
void insertRow(int row, QStandardItem *item) //插入
void appendRow(const QList<QStandardItem *> &items) //在末尾追加
删:
void clear()
bool removeRow(int row, const QModelIndex &parent = QModelIndex())
bool removeColumn(int column, const QModelIndex &parent = QModelIndex())
改:
设置单元格数据
void setItem(int row, int column, QStandardItem *item)
virtual bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole)
virtual bool setHeaderData(int section, Qt::Orientation orientation, const QVariant &value, int role = Qt::EditRole)
查:
获取总行数
virtual int rowCount(const QModelIndex &parent = QModelIndex()) const = 0
获取总列数
virtual int columnCount(const QModelIndex &parent = QModelIndex()) const = 0
获取列名
virtual QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const
QStandardItem *horizontalHeaderItem(int column) const
获取单元格数据
virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const = 0
QStandardItem *item(int row, int column = 0) const