C++ (Qt)void MyTableView::keyPressEvent(QKeyEvent *e){ switch (e->key()) { case Qt::Key_Enter: { if (state() != EditingState || hasFocus()) { if (currentIndex().isValid()) emit activated(currentIndex()); e->ignore(); } // В этом месте пытаюсь активировать нужную ячейку QPersistentModelIndex newCurrent = model()->index(currentIndex().row(), currentIndex().column()); selectionModel()->select(newCurrent, QItemSelectionModel::Select); setFocus(); break;} default: { bool modified = (e->modifiers() & (Qt::ControlModifier | Qt::AltModifier | Qt::MetaModifier)); if (!e->text().isEmpty() && !modified) { if (!edit(currentIndex(), AnyKeyPressed, e)) keyboardSearch(e->text()); } e->ignore(); break; } }}
C++ (Qt)class MySqlTableModel : public QSqlTableModel {public: MySqlTableModel(); bool setData(const QModelIndex &, const QVariant &, int);}; MySqlTableModel::MySqlTableModel() : QSqlTableModel() { setEditStrategy(QSqlTableModel::OnManualSubmit);} bool MySqlTableModel::setData(const QModelIndex &index, const QVariant &value, int role) { bool lResult = false; lResult = QSqlTableModel::setData(index, value, role); if (lResult) { QSqlRecord rec = record(index.row()); rec.setValue(index.column(), value); rec.setGenerated(index.column(), true); lResult = updateRowInTable(index.row(), rec); } return lResult;}