I am using Qt5.
Now I have a QTableView
populated with data from a database table using QSqlTableModel
. I added an extra column with model->insertColumn(n);
.
I would like to be able - using the mouse - to put some checkmarks in some cells of this new added column, as - after exiting the tableView
- I would need to do some further processing for the rows that are marked with the checkmark...
Is there a way of doing this? Please help.
BAD news is: I can add/change all cells in the table (using model->setData(index, "...");
), EXCEPT the cells of the newly added column...
Why is this happening?
That your QSqlTableModel is modifying (or trying to) the corresponding table in the database, and that's likely failing somehow. Is your extra column really corresponding to data coming from the database, or is it synthetized?
Anyhow, two possible solutions are
The idea is to use the proxy/subclass to augment the data (by synthetizing the extra column's data), as well as handle the checked status. In order to mark cells "checkable" you need to return
Qt::ItemIsCheckable
from your model'sflags()
implementation, then the view will calldata()
asking for theQt::CheckStateRole
.