You still want the root index to accepts drops, just not the items so try:
Qt::ItemFlags MyListModel::flags(const QModelIndex&index) const
{
Qt::ItemFlags flags; //= QStringListModel::flags(index);
if (index.isValid())
flags = Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled;
else
flags = Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled | Qt::ItemIsEnabled;
return flags;
}
Qt::ItemFlags MyListModel::flags(const QModelIndex&index) const
{
Qt::ItemFlags flags; //= QStringListModel::flags(index);
if (index.isValid())
flags = Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled;
else
flags = Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled | Qt::ItemIsEnabled;
return flags;
}
To copy to clipboard, switch view to plain text mode
This will work if the root index is invalid (as it usually is). However, if you use setRootIndex you may have to compare against that index instead.
Bookmarks