Hi All,
I've successfully enabled drag and drop in a QTreeWidget (code below).
When you drag an internal QTreeWidgetItem inside the tree, there are
some lines shown where the item goes when dropped. When a url is dragged
over the tree this isn't happening (just a '+' at the cursor).
Is it possible to show these lines while dragging a url (or something
else) over the tree?
And than of course put the new item at the correct position in the tree.
Note: When dragging an internal treeitem, the only type of mimedata that
is available is "application/x-qabstractitemmodeldatalist", but there
seems to be no such thing as a "qabstractitemmodeldatalist" in PySide.
kind regards
Robbert
<code>
import os, sys
from PySide.QtCore import *
from PySide.QtGui import *
from PySide.QtWebKit import *
app = QApplication(sys.argv)
class TreeCtrl(QTreeWidget):
def __init__(self,*args,**kwargs):
QTreeWidget.__init__(self,*args,**kwargs)
self.setAcceptDrops(True)
self.setDragEnabled(True)
self.setDragDropMode(QAbstractItemView.InternalMove)
def dragEnterEvent(self, e):
if e.mimeData().hasUrls():
e.acceptProposedAction()
QTreeWidget.dragEnterEvent(self,e)
def dragMoveEvent(self, e):
QTreeWidget.dragMoveEvent(self,e)
def dropEvent(self, e):
print 'Content of drag object:'
mime = e.mimeData()
for format in mime.formats():
a = mime.data(format)
print '****',format,'--',a,'--',type(a)
if e.mimeData().hasUrls():
print 'Url dropped at item:',self.itemAt(e.pos()),'Do url things
with:',e.mimeData().urls()
QTreeWidget.dropEvent(self,e)
Tree = TreeCtrl ( )
a = QTreeWidgetItem(['Item a'])
Tree.invisibleRootItem().addChild(a)
b = QTreeWidgetItem(['Item b'])
Tree.invisibleRootItem().addChild(b)
c = QTreeWidgetItem(['Item c'])
Tree.invisibleRootItem().addChild(c)
Tree.show()
app.exec_()
</code>
_______________________________________________
PySide mailing list
[email protected]
http://lists.pyside.org/listinfo/pyside