I've run into what looks to be a bug with drag/drop and TreeViews on OSX, which appears to be specific to PyQt, as the same issue does goes away when running equivalent C++ code against the same version of Qt.<br><br>When dragging from one TreeView to another, as soon as one of the QDragMoveEvents gets ignored as a result of hovering over an index that doesn't accept drops, all subsequent QDragMoveEvents will then be rejected as well, regardless of where you're hovering. It looks like what's happening is as soon as event.ignore() is called for the first time on a QDragMoveEvent, the following QDragMoveEvents all have their dropAction() set to 0, whereas it was non-zero before. With a wiped dropAction, the target view rejects them all.<br>
<br>Below a simple example to demonstrate the problem. For what it's worth, it seems the issue is specific to PyQt and OSX, as I have tested it on the following setups:<br><br>OSX 10.6.7, Qt 4.6.3, PyQt 4.7.6 => BUG HAPPENS<br>
OSX 10.6.7, Qt 4.6.3 only (C++ code) => no bug<br>Linux Fedora 8, Qt 4.6.2, PyQt 4.7 => no bug<br><br>#######################################################<br>from PyQt4 import QtCore, QtGui<br><br>a = QtGui.QApplication([])<br>
<br>mainWidget = QtGui.QWidget()<br><br># set up left-hand model/view (drop target)<br>leftView = QtGui.QTreeView(mainWidget)<br>leftModel = QtGui.QStandardItemModel(mainWidget)<br>parentItem = leftModel.invisibleRootItem()<br>
parentItem.setDropEnabled(False)<br>for i in xrange(5):<br> item = QtGui.QStandardItem()<br> # enable dropping on everything except 3rd item<br> if i == 2:<br> item.setDropEnabled(False)<br> item.setText("item %d (UNDROPPABLE)" % i)<br>
else:<br> item.setDropEnabled(True)<br> item.setText("item %d (DROPPABLE)" % i)<br> parentItem.appendRow(item)<br>leftView.setModel(leftModel)<br>leftView.setAcceptDrops(True)<br><br># set up right-hand model/view (drag source)<br>
rightView = QtGui.QTreeView(mainWidget)<br>rightModel = QtGui.QStandardItemModel(mainWidget)<br>item = QtGui.QStandardItem("DRAG ME")<br>item.setDragEnabled(True)<br>rightModel.invisibleRootItem().appendRow(item)<br>
rightView.setModel(rightModel)<br>rightView.setDragEnabled(True)<br>rightView.setDefaultDropAction(QtCore.Qt.MoveAction)<br><br># layout the views<br>layout = QtGui.QHBoxLayout()<br>layout.addWidget(leftView)<br>layout.addWidget(rightView)<br>
mainWidget.setLayout(layout)<br>mainWidget.show()<br><br>a.exec_()<br>