ui->setupUi(this); QStandardItemModel model(4, 4, this); ui->tableView->setModel(&model); for (int row = 0; row < 4; ++row) { for (int column = 0; column < 4; ++column) { QModelIndex index = model.index(row, column); model.setData(index, row + column); } }
void QStandardItemModel::setItem ( int row, int column, QStandardItem * item )virtual void QStandardItem::setData ( const QVariant & value, int role = Qt::UserRole + 1 )
QStandardItemModel model(4, 4, this);...for (int row = 0; row < 4; ++row) for (int column = 0; column < 4; ++column) model.setItem(row, column, new QStandardItem(QString::number(row+column)));