Adding more than one virtual column in proxy model
Hi,
I'm using QSqlTableModel to interact with sqlite database. I have connected QSortFilterProxyModel to filter results in QTableView.
Now I'm wondering how can I add two and more virtual columns that I don't have in model, but I want to have in view.
I have read the topic: http://www.qtcentre.org/threads/8070...l-quot-columns and http://www.qtcentre.org/threads/1565...virtual-column but it adds only one of column.
Which and how should I reimplement QSortFilterProxyModel to add more than one column? More precise, how is realized passing information about position in QTableView to model?
Thanks in advance for every hint.
Re: Adding more than one virtual column in proxy model
Subclass QIdentityProxyModel, reimplement columnCount() to return the number of columns in the original model plus the number of artificial columns you want to have. Then reimplement data() and setData() to store and return data for your artificial columns.
Re: Adding more than one virtual column in proxy model
I forgot to mention that I have also QWidgetMapper connected to add and edit comments, but I'm not sure if it is possible to pass data to model with QIdentityProxyModel.
Second thing is that I don't know how can I get infromation about number of column to insert data, for instance I've got three columns in model: value a, value b and comment. I want to add two columns: a+b and a*b. Problem is that I get only indexes from model and the rest of them are invalid, so it's not possible for me to distinguish column.
Code:
{
if (index.column()>=0) { // Here I get invalid number of column
} else {
return dataFromCell;
}
}
Re: Adding more than one virtual column in proxy model
The column information is carried by the index. If you get invalid column number then apparently you're trying to access the model in an invalid way.
Re: Adding more than one virtual column in proxy model
But the thing is that I don't want to modify my model (data from SQL database), rather I want to add two virtual columns that are not in the model, but they are visible through QTableView and created (calculated) in a proxy.
Re: Adding more than one virtual column in proxy model
Quote:
Originally Posted by
qavaxb
But the thing is that I don't want to modify my model (data from SQL database), rather I want to add two virtual columns that are not in the model
That's why you're implementing a proxy.