[Qt] New LCL override needed badly - TListView.OwnerData support - QTreeWidgetItem::data()

Den Jean Den.Jean at telenet.be
Fri Nov 27 18:22:55 CET 2009

On Friday 27 November  2009 10:11:35 zeljko wrote:
> I want to implement virtual list (TListView->OwnerData, TListView->OnGetData), 
> but for that purpose I need QTreeWidgetItem::data() to be overriden, and our 
> callback added so we have (this code below isn't tested just written to show 
> what we need).Also this override can be used to set any type of roles 
> (text,icon,checkbox) to QTreeWidgetItem.So, please if you can take a look 
> into ASAP.
> With this solution we don't use QTreeWidgetItem_setData(), but our callback 
> just when somebody asks QTreeWidgetItem for data().

strange design, note that setData calls data on children (see qt source code)

I you want to have the data (strings,icons,...) stored in lcl (TOwnerDataListItem) you should
only override ::data (and never use setdata as it would set data at the wrong
side, namely Qt) 

I you want to store the data in Qt, why do you not use setdata in the first place, 
whenever data is set in TListView calls. 

strange, ...

also note that you should call     void emitDataChanged();
if you change data at the lcl side to notify qt (wiothout ever using setdata).

FYI: data in qt is stored in private (undocumented)
..... ./gui/itemviews/qtreewidget.h
QVector< QVector<QWidgetItemData> > values;

class QWidgetItemData
    inline QWidgetItemData() : role(-1) {}
    inline QWidgetItemData(int r, QVariant v) : role(r), value(v) {}
    int role;
    QVariant value;
    inline bool operator==(const QWidgetItemData &other) { return role == other.role && value == other.value; }

(temp files, will be removed after release)

kind regards,

Den Jean

More information about the Qt mailing list