QListView view;
QStandardItemModel *model = new QStandardItemModel(&view);
view.setModel(model);
for(int i = 0; i < 5; i++) {
QStandardItem *item = new QStandardItem(QString::number(i));
model->appendRow(item);
QModelIndex index = model->indexFromItem(item);
model->setData(index,i,Qt::DisplayRole);
}
view.show();
model->setData(index,i,Qt::DisplayRole);
这里设置的是int型value,对应的是QSpinBox
修改:
model->setData(index,QString::number(i),Qt::DisplayRole);
这里设置的是字符型value,对应的是QLineEdit