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

zeljko zeljko at holobit.net
Fri Nov 27 10:11:35 CET 2009

Hi all,

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().


#include <QtGui/qtreewidget.h>

class QLCLTreeWidgetItem : public QTreeWidgetItem {


  // need constructors with QTreeWidgetH + type and QTreeWidgetItemH + 
  // type and QLCLTreeWidgetItemH + type
  QLCLTreeWidgetItem(QTreeWidget *parent = 0) : QTreeWidgetItem(parent) {
    dataOverride.func = NULL;

  void override_data(const QOverrideHook hook) {
    dataOverride = hook; 


  QOverrideHook dataOverride;

  QVariant data(int column, int role) const {

    if (dataOverride.func) {
      // now we can ask TListView->Items->Caption and then 
      typedef void (*func_type)(void *data, int column, int role);
      (*(func_type)dataOverride.func)(dataOverride.data, column, role);


    return QTreeWidgetItem::data(column, role);





More information about the Qt mailing list