Modifying a cell in TableView using QSqlQueryModel
Unsolved
General and Desktop
-
-
I need to query a database and load a tableView. Most of the columns are displayed as in the database. However, one column needs to be changed from a number to a text string.
The function is very simple. How do I connect this function to the table?
Thanks
- One possibility is a
QAbstractProxyModel
on top of the SQL model to which the view now attaches which maps the value to a string for the view. - Another is a
QStyedItemDelegate
to do the mapping just for diaply in the view. - And a third is if the mapped strings are held in another SQL table to use a
QSqlRelationalTableModel
if yourQSqlQueryModel
can be aQSqlTableModel
.
- One possibility is a
-
- One possibility is a
QAbstractProxyModel
on top of the SQL model to which the view now attaches which maps the value to a string for the view. - Another is a
QStyedItemDelegate
to do the mapping just for diaply in the view. - And a third is if the mapped strings are held in another SQL table to use a
QSqlRelationalTableModel
if yourQSqlQueryModel
can be aQSqlTableModel
.
@JonB Maybe a QIdentityModel will work also.
- One possibility is a
-
@JonB Maybe a QIdentityModel will work also.
@Christian-Ehrlicher
AQIdentityProxyModel
is derived fromQAbstractProxyModel
per my first bullet :) Yes, one would start from aQIPM
as an example of aQAPM
(does the groundwork for all the identical columns) and just change the one column whose values need mapping.