Hi,
after a lot of research and trial and error, i hit a dead end. What i want is a QTreeView that has drag&drop enabled, but only file elements inside should be dragable (and not accept drops) and only folder elements should accept drops, and not be dragable.
if i configure the QTreeView like this
ptrTreeView->setDragEnabled(true);
ptrTreeView->setAcceptDrops(true);
ptrTreeView->setDragEnabled(true);
ptrTreeView->setAcceptDrops(true);
To copy to clipboard, switch view to plain text mode
or like this
ptrTreeView->setDragDropMode(QAbstractItemView::DragDropMode::DragDrop);
To copy to clipboard, switch view to plain text mode
and set the items to
ptrFileItem->setDragEnabled(true);
ptrFileItem->setDropEnabled(false);
ptrFileItem->setDragEnabled(true);
ptrFileItem->setDropEnabled(false);
To copy to clipboard, switch view to plain text mode
and the folders to
ptrFolderItem->setDragEnabled(false);
ptrFolderItem->setDropEnabled(true);
ptrFolderItem->setDragEnabled(false);
ptrFolderItem->setDropEnabled(true);
To copy to clipboard, switch view to plain text mode
every item is still drag and dropable as if the the configuration of the tree overrides the individual configuration of the items. Do you guys know of a way where this is possible?
Another approach I tried is to let every item have both drag&drop ability but to modify the drop indicator and block/allow the actual drag&dropping in the drag&drop functions, but i did not succeed wit that either.
I created a custom model class derived from QStandardItemModel in which the flags fundtion is overridden
{
Q_OBJECT
public:
virtual Qt
::ItemFlags flags
(const QModelIndex &index
) const Q_DECL_OVERRIDE;
}
class MyModel: public QStandardItemModel
{
Q_OBJECT
public:
MyModel(QWidget *parent = Q_NULLPTR) : QStandardItemModel(parent) {};
virtual Qt::ItemFlags flags(const QModelIndex &index) const Q_DECL_OVERRIDE;
}
To copy to clipboard, switch view to plain text mode
In the flags function i analyzed the current Item and modified the Qt::ItemFlags so that Drag and Drop was enabled/disabled but still the drop indicator was shown while hovering over all the file/folder items. Is this approach wrong and if so, do you know of a working one?
Bookmarks