Unsolved QTableView make one colmum editable
-
I found a lot in the internet about it, but I have one problem.
I made a QFilterSortProxyModel and want overwrite the flags.
Is there a more easy solution for this common task ?class SpecialProxy: public QSortFilterProxyModel {public: SpecialProxy(QObject* o):QSortFilterProxyModel(o) {} virtual Qt::ItemFlags flags(const QModelIndex& index) const override { Qt::ItemFlags result = this->sourceModel()->flags(index); if (index.column() == 3) { result |= Qt::ItemIsEditable; } return result; }
Must I enable all edit flags in the QTableView and disable the editable-flag in proxy model ? How get I the default flags ?
The sourcemodel seen to have not the correct flags! If I use the code above no selection of the whole table works (nor editing works). Why that ? -
Just call the base class version
class SpecialProxy: public QSortFilterProxyModel {public: SpecialProxy(QObject* o):QSortFilterProxyModel(o) {} virtual Qt::ItemFlags flags(const QModelIndex& index) const override { Qt::ItemFlags result = QSortFilterProxyModel::flags(index); if (index.column() == 3) result |= Qt::ItemIsEditable; else result &= ~Qt::ItemIsEditable; // All other columns not editable return result; }
-
Hello @VRonin,
ok thank you this works.But the changing in the database does not. After refresh I get once a again the same data.
TPModel = new QSqlTableModel (this); TPModel->setTable("qryTransportGUI"); SpecialProxy *Proxy = new SpecialProxy(this); Proxy->setSourceModel(TPModel); ui->TPView->setModel(Proxy);
The edit action does not write in the queried data !
-
Hi,
Did you check the edit strategy of your model ?