Added a new QTableView to the form, “zamapil” on the table. The problem is that in the program it is impossible to edit the cells. There was no such problem with other tables, editing there immediately worked. Code:

 void MethodicWorkWidget::setupMethod3Model() { method3Model = new ExtSqlModel(this); method3Model->setTable("methodworks3"); method3Model->setEditStrategy(QSqlTableModel::OnFieldChange); int typeInd = method3Model->fieldIndex("typeid"); method3Model->setRelation(typeInd, QSqlRelation("methodworks3types", "id", "Name")); method3Model->setFilter("teacherid="+QString::number(teacherID));//+" AND YearID="+QString::number(yearID)); method3Model->setHeaderData(typeInd, Qt::Horizontal, tr("Вид")); method3Model->setHeaderData(method3Model->fieldIndex("discipline"), Qt::Horizontal, tr("Дисциплина")); method3Model->setHeaderData(method3Model->fieldIndex("theme"), Qt::Horizontal, tr("Тема")); method3Model->setHeaderData(method3Model->fieldIndex("date"), Qt::Horizontal, tr("Дата проведения")); method3Model->setHeaderData(method3Model->fieldIndex("value"), Qt::Horizontal, tr("Балл")); ui.label_2->setText(QString::number(teacherID)); method3Model->setSort(0, Qt::AscendingOrder); //populate and check if (!method3Model->select()) { QMessageBox::critical(NULL, tr("Ошибка обращения к базе"), tr( "Произошла ошибка при выборе руководства:\n")+manageModel->lastError().text()); } ui.method3View->setModel(method3Model); ui.method3View->hideColumn(method3Model->fieldIndex("id")); ui.method3View->hideColumn(method3Model->fieldIndex("teacherid")); ui.method3View->setItemDelegateForColumn(typeInd, new QSqlRelationalDelegate(ui.method3View)); ui.method3View->resizeColumnsToContents(); connect(ui.method3AddButton, SIGNAL(clicked()), this, SLOT(method3Add())); connect(ui.method3DelButton, SIGNAL(clicked()), this, SLOT(method3Del())); ui.method3DelButton->setEnabled(method3Model->rowCount()!=0); if(UserInfo::role() == UserInfo::Guest){ ui.method3AddButton->setEnabled(false); ui.method3DelButton->setEnabled(false); ui.method3View->setEditTriggers(QAbstractItemView::NoEditTriggers); } } 

QT 4.5.2, QTCreator 1.2.1

    1 answer 1

    Check in the ExtSqlModel class whether you redefined the Qt::ItemFlags flags(const QModelIndex & index) const method Qt::ItemFlags flags(const QModelIndex & index) const . In this method, for the fields that you want to edit, you need to cock the Qt::ItemIsEditable check box.

    • The flags were incorrectly redefined, thanks! - DoSofRedRiver