18 QHash<QModelIndex, QVariant> m_hash;
22 : QAbstractTableModel(pobj)
24 , m_nColumns(nColumns)
28 QVariant
data(
const QModelIndex& index,
int nRole)
const 30 if (!index.isValid()) {
34 QString(
"%1,%2").arg(index.row() + 1).arg(index.column() + 1);
35 return (nRole == Qt::DisplayRole || nRole == Qt::EditRole)
36 ? m_hash.value(index, QVariant(str))
41 const QVariant& value,
45 if (index.isValid() && nRole == Qt::EditRole) {
46 m_hash[index] = value;
47 emit dataChanged(index, index);
63 Qt::ItemFlags
flags(
const QModelIndex& index)
const 65 Qt::ItemFlags
flags = QAbstractTableModel::flags(index);
66 return index.isValid() ? (
flags | Qt::ItemIsEditable)
72 int main(
int argc,
char *argv[])
74 QApplication app(argc, argv);
78 tableView.setModel(&model);
bool setData(const QModelIndex &index, const QVariant &value, int nRole)
int columnCount(const QModelIndex &) const
int main(int argc, char **argv)
TableModel(int nRows, int nColumns, QObject *pobj=0)
int rowCount(const QModelIndex &) const
Qt::ItemFlags flags(const QModelIndex &index) const
QVariant data(const QModelIndex &index, int nRole) const