I have a QTreeView with a QStandardItemModel implementing a simple "notebook" type of application (ie: a bunch of notes inside a bunch of folders).
Everything is fine except for internally drag/dropping a folder in the treeview when all the notes in the dragged folder get lost.
This is a known bug and is detailed here: Drag and drop in QTreeView with QStandardItemModel and InternalMove loses children
Without this functionality I'm truly stuck, so I'm now subclassing QStandardItemModel
class QNotesStandardItemModel : public QStandardItemModel
To copy to clipboard, switch view to plain text mode
and trying to manually sort things out in:
bool QNotesStandardItemModel
::dropMimeData ( const QMimeData * data, Qt
::DropAction action,
int row,
int column,
const QModelIndex & parent
){ if (!data->hasFormat("application/x-qabstractitemmodeldatalist")) return false;
QByteArray encodedData
= data
->data
("application/x-qabstractitemmodeldatalist");
bool QNotesStandardItemModel::dropMimeData ( const QMimeData * data, Qt::DropAction action, int row, int column, const QModelIndex & parent ){
QStringList list = data->formats();
if (!data->hasFormat("application/x-qabstractitemmodeldatalist")) return false;
QByteArray encodedData = data->data("application/x-qabstractitemmodeldatalist");
To copy to clipboard, switch view to plain text mode
And now I'm stuck!
QUESTION 1: encodedData contains a QList<QModelIndex> but how do I get at it? I want a kind of "qobject_cast<QModelIndexList>(encodedData)" type of thing! Just can't see how though.
QUESTION 2: Is there an easy way of working round the "lost children" problem? I really wanted to keep this application as simple as possible and not have to subclass standard classes which generally work fine out of the box.
Bookmarks