PDA

View Full Version : QStandardItemModel Drag n Drop Behavior with QTreeView



johnmidd
5th November 2009, 19:53
I have a QTreeView backed by a QStandardItemModel. I want to display instances of my class TreeItem (subclass of QStandardItem) in the QTreeView. However, when an item gets dragged and dropped (moved) around the QTreeView, the TreeItem instance is deleted and a new generic QStandardItem instance is placed in the drop location. Is there a way I can prevent the destruction of the TreeItem? I just want the instance to be moved to the new position in the tree (and model).

I've experimented with all the settings on QTreeView and QStandardItemModel but can't get what I want.

I've even tried QStandardItemModel::setItemPrototype(new TreeItem()) to see if at least a new TreeItem will be created instead of a generic QStandardItem. (Yes, I implemented TreeItem::clone()). But no luck.

Is there a way I can get TreeItems to move around the tree and model without the destruction and creation of new item instances?

(Using Qt 4.5 on Mac OS Leopard)