PDA

View Full Version : QTreeView - drop indicator not showing for an external drag from another tree view



alketi
3rd March 2015, 21:55
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.


void MyTreeView::dragMoveEvent(QDragMoveEvent *event)
{
// Call base class -- this shows the drop indicators
QTreeView::dragMoveEvent(event);

if (event->mimeData()->hasFormat("text/plain") )
{
event->acceptProposedAction();
event->accept();
}
else
{
event->ignore();
}
}

wysota
3rd March 2015, 22:35
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.

alketi
3rd March 2015, 23:42
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.

wysota
4th March 2015, 01:03
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.

alketi
4th March 2015, 20:39
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?

wysota
4th March 2015, 22:02
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.


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?