viewTest_ = new QTreeView(this);model_ = new GuiModelTree(viewTest_); // от QStandardItemModelmodel_->setDataModel();viewTest_->setModel(model_);
void GuiModelTree::setDataModel(){ for (int i = 0; i < 10; ++i) { int countRow = rowCount(); if (countRow == 0) { insertRows(countRow, 1); } else { QModelIndex ind = index(countRow - 1, 0); insertRows(countRow, 1, ind); } QModelIndex ind = index(countRow, 0); setData(ind, true, Qt::DisplayRole); }}
An example usage of QStandardItemModel to create a table: QStandardItemModel model(4, 4); for (int row = 0; row < 4; ++row) { for (int column = 0; column < 4; ++column) { QStandardItem *item = new QStandardItem(QString("row %0, column %1").arg(row).arg(column)); model.setItem(row, column, item); } }
An example usage of QStandardItemModel to create a tree: QStandardItemModel model; QStandardItem *parentItem = model.invisibleRootItem(); for (int i = 0; i < 4; ++i) { QStandardItem *item = new QStandardItem(QString("item %0").arg(i)); parentItem->appendRow(item); parentItem = item; }
An example usage of QStandardItemModel to create a tree: QStandardItemModel *model = new QStandardItemModel(); QModelIndex parent; for (int i = 0; i < 4; ++i) { parent = model->index(0, 0, parent); model->insertRows(0, 1, parent); model->insertColumns(0, 1, parent); QModelIndex index = model->index(0, 0, parent); model->setData(index, i); }