QTreeWidgetItem *rootItem = new QTreeWidgetItem(treeWidget);QTreeWidgetItem *item = new QTreeWidgetItem(rotItem);QTreeWidgetItem *item1 = new QTreeWidgetItem(item, ...);QTreeWidgetItem *item2 = new QTreeWidgetItem(item, ...);QTreeWidgetItem *item3 = new QTreeWidgetItem(item, ...);
MyItemDelegate* d = new MyItemDelegate(this);for(int i=0; i<3; i++){treeWidget->setItemDelegateForRow(i+2, d);}
C++ (Qt)for( int i = 0; i < 3; i++ ){ MyItemDelegate *d = new MyItemDelegate( this ); treeWidget->setItemDelegateForRow( i+2, d );}
topLevelItem1 |-----item1 |-----item2topLevelItem2 |-----anotherItem1 |-----anotherItem2
void paint ( QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index ) const{ ... if( index.parent().isValid() ) { if( index.parent().row() == 0 ) paintRow0( painter, option, index ); else paintRow1( painter, option, index ); } ...}