dragEnabled is true, and these are the flags and mimeData methods (pretty much as in the documentation:
Qt
::ItemFlags ThemaLesModel
::flags(const QModelIndex &index
) const{
Qt::ItemFlags defaultFlags = sourceModel()->flags(mapToSource(index));
if (index.isValid())
return Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled | defaultFlags;
return defaultFlags;
}
QMimeData *ThemaLesModel
::mimeData(const QModelIndexList
&indexes
) const {
if (index.isValid()) {
QString text
= data
(index, Qt
::DisplayRole).
toString();
stream << text;
}
}
mimeData->setData("application/vnd.text.list", encodedData);
return mimeData;
}
Qt::ItemFlags ThemaLesModel::flags(const QModelIndex &index) const
{
Qt::ItemFlags defaultFlags = sourceModel()->flags(mapToSource(index));
if (index.isValid())
return Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled | defaultFlags;
return defaultFlags;
}
QMimeData *ThemaLesModel::mimeData(const QModelIndexList &indexes) const
{
QMimeData *mimeData = new QMimeData();
QByteArray encodedData;
QDataStream stream(&encodedData, QIODevice::WriteOnly);
foreach (const QModelIndex &index, indexes) {
if (index.isValid()) {
QString text = data(index, Qt::DisplayRole).toString();
stream << text;
}
}
mimeData->setData("application/vnd.text.list", encodedData);
return mimeData;
}
To copy to clipboard, switch view to plain text mode
If I use 'SelectRows', than I can't do anything. Using SelectItems, it works, but only for the original data rows, not for the 'virtual' ones I introduced myself for the grouping. While debugging, I saw that apparently it's the selectionModel that tells the view there are no selections when in SelectRows mode.
Bookmarks