#include "StdAfx.h" #include "MyModel.h" MyModel::MyModel(QObject *parent) : QStandardItemModel(parent) { } MyModel::~MyModel() { } bool MyModel::dropMimeData (const QMimeData* data, Qt::DropAction action, int row, int col, const QModelIndex &parentIndex) { ////////////////////////////////////////////////////////////////////////// // If this routine returns true, everything works as expected. // HOWEVER, if we return false for any reason, the DROP does not occur, // but the item being DRAGGED still disappears!!! (I assume this is // because we setDefaultDropAction(Qt::MoveAction) on the treeView). // // In the example below, I was hoping to disallow drops if we were at the // top level of the tree (i.e. our parentIndex was inValid) and I thought // that returning false would do the trick. // // Is this a bug in Qt, or am I missing something??? ////////////////////////////////////////////////////////////////////////// bool result = false; if (parentIndex.isValid()) { if (data->hasFormat("application/x-qstandarditemmodeldatalist")) { result = __super::dropMimeData (data, action, row, col, parentIndex); // Call the base class implementation... } } return result; }