I’m using a persistent model with a QTreeView subclass. The model is filled and emptied based on a ‘selection’ the user makes in another widget.

I need advice about deleting the delegates of the view when the user makes a new 'selection'. I need to do this because the data types in the model are not consistent from one ‘selection’ to the next and therefore, the type of delegate needs to change.

As an example; with selection_1, the row 0 value is an integer but for selection_2 row 0 is an enumeration and for selection_3 row 0 might be a string: each selection requires a different delegate

Is this the best way to accomplish the removal/deletion of delegates?

Qt Code:
  1. // Get the current delegate
  2. MyDelegate* delegate = (MyDelegate*)myTreeView->itemDelegateForRow( rowNum );
  3. // Remove the delegate from the view
  4. myTreeView->setItemDelegateForRow( rowNum, NULL );
  5. delete delegate;
To copy to clipboard, switch view to plain text mode 
Qt Commercial 4.6.2
Windows (XP SP3 / 7)