View Full Version : Persistent (changing) model and delegate deletion

23rd September 2010, 16:51
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?

// Get the current delegate
MyDelegate* delegate = (MyDelegate*)myTreeView->itemDelegateForRow( rowNum );
// Remove the delegate from the view
myTreeView->setItemDelegateForRow( rowNum, NULL );
delete delegate;

Qt Commercial 4.6.2
Windows (XP SP3 / 7)