QTreeView - drop indicator not showing for an external drag from another tree view
I have the drag and drop indicators working fine for internal moves within the same tree view (say TreeView1).
But, the indicators are not visible when dragging from an external tree view (TreeView2 -> TreeView1).
Any idea what is needed to show the drop indicators when dragging from an external tree view?
Here's my code for the tree view that is the drop target.
Code:
{
// Call base class -- this shows the drop indicators
if (event->mimeData()->hasFormat("text/plain") )
{
event->acceptProposedAction();
event->accept();
}
else
{
event->ignore();
}
}
Re: QTreeView - drop indicator not showing for an external drag from another tree vie
Basically all you need to do is implement drag&drop related functions in the model. You don't have to do anything with the view.
Re: QTreeView - drop indicator not showing for an external drag from another tree vie
Hi wysota, thank you, but maybe I wasn't clear enough --
Drag & drop works, both internal to the tree view and from one tree view to another.
-- When dragging (moving) a row internally, I see the drop indicators.
-- When dragging (copying) a row from an external tree view, I do not see the drop indicators (but the drop action still works).
My question is how do I show the drop indicators when dropping from one tree view to another tree view?? (I see them when dropping within the same tree view)
Thank you.
Re: QTreeView - drop indicator not showing for an external drag from another tree vie
Quote:
My question is how do I show the drop indicators when dropping from one tree view to another tree view??
You do that by properly implementing drag&drop operations in the models without modifying the views.
Re: QTreeView - drop indicator not showing for an external drag from another tree vie
wysota, none of the overridden methods: flags(..), supportedDropActions(..), etc. in TreeModel #2 are getting called when the dragging begins from TreeModel #1.
I assume that's why the indicator isn't appearing. I can still successfully make the drop, but I don't see the indicator....
When dragging&dropping internally in TreeModel #2, all the overridden methods are called, and the indicator appears.
Can you provide some clue as to what needs to be implemented to see the indicator when dragging from TreeModel #1 into TreeModel #2?
Re: QTreeView - drop indicator not showing for an external drag from another tree vie
Quote:
Originally Posted by
alketi
wysota, none of the overridden methods: flags(..), supportedDropActions(..), etc. in TreeModel #2 are getting called when the dragging begins from TreeModel #1.
You should implement QAbstractItemModel::mimeTypes(), QAbstractItemModel::mimeData(), QAbstractItemModel::canDropMimeData() and QAbstractItemModel::dropMimeData(). As well as flags(), of course.
Quote:
Can you provide some clue as to what needs to be implemented to see the indicator when dragging from TreeModel #1 into TreeModel #2?
You read "Using Drag and Drop with Item Views", didn't you?