<p>Hi,&nbsp;</p><p>I&#39;m having trouble performing a task that I thought should be very common, but that instead appears to be an unusual need. &nbsp;In short, I have a database table that has three columns: let&#39;s say they are ID, Name and Savings, in this order. Now, I would like to retrieve the table and for that I can use a QSqlTableModel, that I can then visualize with a table view. But what if I want to achieve the following (I&#39;m only interested in the model to be read-only):</p>
<p>a) visualize the table with column 1 and 2 swapped, so that the table that I look at shows ID, Savings, Name?</p><p>b) show one more column in the table, which does not exist in the database. The column contains custom data that should be set by the user through a dialog for example.&nbsp;</p>
<p>Am I missing something terribly evident here? So far I&#39;ve tried the following, without any success:</p><p>1. use QSqlRelationalTableModel (I actually have foreign keys), and use the&nbsp; insertColumn method. That kind of worked, but when I try to fill the column with setData I can either fill the previous, or the following column.</p>
<p>2. use QProxyModel, with no success whatsoever.</p><p>3. use QSqlRelationalTableModel, loop through each element of the model, and fill a QTableWidget with the data. Then add a column to the QTableWidget and fill it with the additional data I wanted to display. This of course works, but it appears rather cumbersome and inefficient. Furthermore, it doesn&#39;t follow the Model/View philosophy at all.&nbsp;</p>
<p>Any help would be much appreciated. Sorry for the verbose email.&nbsp;</p><p>Mattia</p>