You really don't have to touch the event handlers here. All you need is already implemented by the abstract view class -- take a look at its sources, if you don't believe us, for example:
{
if (d_func()->canDecode(event)) {
event->accept();
setState(DraggingState);
} else {
event->ignore();
}
}
void QAbstractItemView::dragEnterEvent(QDragEnterEvent *event)
{
if (d_func()->canDecode(event)) {
event->accept();
setState(DraggingState);
} else {
event->ignore();
}
}
To copy to clipboard, switch view to plain text mode
All things you need to reimplement are:
bool QTreeWidget::dropMimeData ( QTreeWidgetItem * parent, int index, const QMimeData * data, Qt:ropAction action ) [virtual protected]
Handles the data supplied by a drag and drop operation that ended with the given action in the index in the given parent item.
See also supportedDropActions().
QStringList QTreeWidget::mimeTypes () const [virtual protected]
Returns a list of MIME types that can be used to describe a list of treewidget items.
See also mimeData().
QMimeData * QTreeWidget::mimeData ( const QList<QTreeWidgetItem *> items ) const [virtual protected]
Returns an object that contains a serialized description of the specified items. The format used to describe the items is obtained from the mimeTypes() function.
If the list of items is empty, 0 is returned rather than a serialized empty list.
First method does the actual drop, second returns a list of mime-types which can be dropped onto the widget (maybe you forgot to implement it -- that's why I asked about that "stop sign" in my previous post) and the last one returns a pointer to an object describing a particular item according to mime-types returned by the previous method.
You can take a look at equivalents of those three methods in the QAbstractItemModel class. And also remember that QTreeWidget is just a wrapper over QTreeView containing an internal model representation. For example:
const QMimeData *data, Qt
::DropAction action
) {
if (parent) idx = indexFromItem(parent);
return model()->QAbstractItemModel::dropMimeData(data, action , index, 0, idx);
}
bool QTreeWidget::dropMimeData(QTreeWidgetItem *parent, int index,
const QMimeData *data, Qt::DropAction action)
{
QModelIndex idx;
if (parent) idx = indexFromItem(parent);
return model()->QAbstractItemModel::dropMimeData(data, action , index, 0, idx);
}
To copy to clipboard, switch view to plain text mode
Bookmarks