PDA

View Full Version : Custom Delegate in multi hierarchy QTreeView



btbt9527
5th January 2016, 18:28
I have a multi hierarchy QTreeView (currently 3 levels, will be more depends),
I created 3 different delegates (delegate A/B/C) for each level
But how do I apply the delegate to the QTreeView properly?
The following pic shows what I want:



>Row 0 -------------------- delegate A
>Row 1 -------------------- delegate A

^Row 2 -------------------- delegate A
^Row 20 ----------------- delegate B
Row 200 -------------- delegate C
Row 201 -------------- delegate C
Row 202 -------------- delegate C

^Row 21 ----------------- delegate B
Row 210 -------------- delegate C
Row 211 -------------- delegate C
Row 212 -------------- delegate C


This function:
QAbstractItemView::setItemDelegateForRow(int row, QAbstractItemDelegate * delegate);

With this function, I can only assign the delegate for the first level of the TreeView.
And its children (level 2, level 3) are gonna share the same delegate with level 1

How do I assign the delegate B to Row 20 and Row 21?
How do I assign the delegate C to Row 200, Row 201, Row 202......