Hello
I have a question about QAbstractProxyModel. Suppose there is model and view.
I want to use a proxy between model and view which multiplies a column of data in model by a value. Is it possible?
Thanks
Hello
I have a question about QAbstractProxyModel. Suppose there is model and view.
I want to use a proxy between model and view which multiplies a column of data in model by a value. Is it possible?
Thanks
alizadeh91 (3rd December 2012)
Should i re-implement specific methods for that?
Last edited by alizadeh91; 3rd December 2012 at 14:43.
Yes, you need to implement all pure virtual methods and reimplement those virtual methods that govern the behaviour you want to change. Note that if you're not used to proxy models and you only wish to change data returned by the base model, consider subclassing QSortFilterProxyModel instead of QAbstractProxyModel.
alizadeh91 (3rd December 2012)
Thanks for useful hints,
That's true, i can use QSortFilterProxyModel. But in this case what methods should i re-implement?
Since you don't want to change the structure of the data, I'd suggest to have a look at QIdentityProxyModel.
So you'll only have to reimplement data and can forward any call that is not the display role and for the column which you want to change.
Cheers,
_
Here is what i want to do, see if can suggest me best way:
I have a view and a custom header with comboBox for every column.
In the comboBox there are some units(e.g kilogram,gram, pound, ...). if user change the unit, the content of that column have to be changed according to unit.
Since just the unit of data is changed i don't want to change the model. I just want to display its equivalent in desired unit.
So i thought best way to implement this is proxy. may be if i use a proxy in model i can fix the model but just change the displaying data in proxy.
Is that true?
Is there better solutions?
Thanks wysota, Yes i'm reading! i just want to clear the problem!
Thanks again wysota, I've implemented the data() and it's ok except that the table doesn't update itself when i modify values returned by the model. I've evenIf you wish to modify values returned by the model, reimplement data().
try emit dataChanged() signal but i'm getting a weird error:
Qt Code:
error: C2662: 'QAbstractItemModel::dataChanged' : cannot convert 'this' pointer from 'const TCustomProxyModel' to 'QAbstractItemModel &' Conversion loses qualifiersTo copy to clipboard, switch view to plain text mode
(TCustomProxyModel: my custom proxy model)
Just another thing: when i click on table the table update itself!!!
Last edited by alizadeh91; 15th December 2012 at 09:22.
Bookmarks