PDA

View Full Version : Process the display data before displaying in QTreeView



babu198649
22nd June 2009, 13:59
HI
i have set a model for the read only QTreeView .I want to show the data in the QTreeView after some processing of the models data has been done to display rather than showing it as the same in the model. The QAbstractItemDelegate class does not have any function to process the data before display .Any suggestions are appreciated.

vieraci
22nd June 2009, 14:17
Create your own custom model from QStandardItemModel, subclass data() to modify what is displayed and setData() to return whatever you want.

babu198649
22nd June 2009, 17:12
Different view has to display different data based on the same model.So returning data for a particular view from the data() function is not possible.

Lykurg
22nd June 2009, 17:34
Different view has to display different data based on the same model.So returning data for a particular view from the data() function is not possible.

No problem. You have the "original" model called modelOriginal and two views A and B which displays the data of modelOriginal in different ways. So create two models modelForA and modelForB like this:

class modelForA : public modelOriginal
{...};

QVariant modelForA::data(...)
{
QVariant originalData = modelOriginal::data(...);
// here alter the data for the model A and return it
return modifiedData;
}



Voilà ;)

babu198649
22nd June 2009, 20:14
Thank you,
Really its a good idea, i all give it a try.

aamer4yu
23rd June 2009, 06:21
And if you are using QTreeWidget, you could modify the data in delegates.
You need to subclass QItemDelegate or QStyledItemDelegate and override the drawDisplay() or paint() function respectively.