[solved]Disabling editing on certain columns in QSqlTableModel
-
Hey,
I was working with QSqlTableModel, and I was wondering is there a way that we can disable editing on a certain columns, also on some other column can I receive a signal when user double clicks to make changes, so that I can execute some set of codes.
Thanks in advance. :) -
Hi,
You need to subclass QSqlTableModel and reimplement the flags method
Do you mean something like the doubleClicked signal ?
-
@SGaist said:
Hi,
You need to subclass QSqlTableModel and reimplement the flags method
Do you mean something like the doubleClicked signal ?
Hey SGaist, thanks for replying
Ok i need to learn subclassing, any tuts?
also, there are some fields i want to the user edit but i want to keeps its back up, also change others things with respect to the edits made by user, i guess i can use doubleClicked signal. -
If you want to react on the modified data, then you should rather check the model's dataChanged signal
-
@SGaist said:
If you want to react on the modified data, then you should rather check the model's dataChanged signal
this->connect(modelC, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(dataChangedEdit(QModelIndex a,QModelIndex b)));
here modelC is the subclassed QSqlTableModel and dataChangedEdit is the Slot with I declared bt it doesn't work, whats wrong?
Also it says, QObject::connect: No such slot MainWindow::dataChangedEdit(QModelIndex a,QModelIndex b) in ....
-
Remove a and b from your connect statement, only the type of the parameter should be there not their name. If using Qt 5, you should consider using the new syntax.
Also note that dataChangeEdit should rather be
dataChangedEdit(const QModelIndex& a, const QModelIndex& b)
that will avoid needles copies -
You're welcome !
Since you have it working now, please update the thread title prepending [solved] so other forum users may know a solution has been found :)