PDA

View Full Version : QAbstractProxyModel and "virtual" columns



tranfuga25s
15th July 2007, 15:28
Can reimplement QAbstractProxyModel to add a new column that needs to be calculated?

The specific case is that I have a model that has the product, qty and price and need to add a new column with the value (price*qty).
Can I use QAbstractProxyModel to add that column, reimplementing all the functions that are necesaries?

If there is another way to do it?

thanks in advance

Michiel
15th July 2007, 22:18
Absolutely. You can do it that way. Just reimplement all the abstract methods from QAbstractItemModel. Of special interest to you are the columnCount() and data() functions.

However, if you can, you might want to just add that column to the original model, and only use a proxy if you want to filter it out somewhere. Would be easier to program, I think.

tranfuga25s
15th July 2007, 22:57
Another question:

How can I now when a item is updated from the QTableView itself, not the model?
I need to update a field to total outside the tableview but cant find a suitable signal to connect to a slot... :(

I`m not reimplementing any method for my view...

Thanks again! :D

wysota
15th July 2007, 23:39
When an item is edited in a view, the view updates the model which in turn emits the dataChanged() signal. So if you want to update something which is not part of the model, connect to that signal. If you want to update some other item that is part of the model, I suggest you do that from within setData() reimplementation.