Use QAbstractProxyModel to add extra "virtual" columns in a table

465 views Asked by At

I have some data which are stored in a variable "myStorage" (a QVector).

I use a QAbstractTableModel to display these data in a QTableView : each entry in the QVector is a row in the table and each field in "myStruct" is a column.

Now I want to display more information, in a new column, without any modification to "myStruct" or to my model.

So I tried to make a new model class, derived from QAbstractProxyModel, which should add the new "virtual" column.

(For example, this column could be the average of 2 existing fields in "myStruct")

But I can't make it work : in the worst case, the program crash, in the best case, I have the right number of columns (one more than in the proxied model) and the right headers, but the data are shifted and the last column is empty.

Is there any minimal/simple example of a "add virtual column proxy model" working implementation ?

Should I use QIdentityProxyModel as a base class instead of QAbstractProxyModel ?

Thanks

0

There are 0 answers