Search code examples
c++qtmodelqtguiqtcore

Display int as QString in QTableView column


I have a QTableView linked to a QSqlTableModel. In this table, there is a column that is a integer. Each value of this one matches with a QString. I already used a QComboBox delegate in order to select the QString when editing. But when the value is edited, it is displayed as an integer.

What I want to do is to display the value as a QString with the corresponding integer value.

I looked in QAbstractProxyModel class but I am not totally sure that it can solve my problem.

Can you confirm this way (subclassing QAbstractProxyModel) or using another one?

Thanks for your answers.


Solution

  • You should reimplement your delegate paint method to display text.

    You can check classic star delegate example. In your case everything is much simplier: you should draw just a text.