Ok so I hacked around, and I got something working but its just that.. a hack.. can anybody give me some more tips on how to make this not use a bad hack?

thanks in advance

-john

Qt Code:
  1. #!/usr/local/bin/python
  2.  
  3. # dragdrop.py
  4.  
  5. import sys
  6. from PyQt4 import QtGui,QtCore
  7.  
  8. class treeWidgetClass(QtGui.QTreeWidget):
  9.  
  10. def mimeTypes(self):
  11. types = QtCore.QStringList()
  12. types.append("text/plain")
  13. return types
  14.  
  15. def fmimeData(text):
  16. customMimeData = QtCore.QMimeData()
  17. customText = QtCore.QString()
  18. customMimeData.setText(customText)
  19. return customMimeData
  20.  
  21. def mousePressEvent(self, event):
  22.  
  23. #list = QtCore.QStringList()
  24. #list = self.mimeTypes()
  25. #for a in list:
  26. # print a
  27.  
  28. button = event.button()
  29. item = self.itemAt(event.x(), event.y())
  30.  
  31. if item:
  32. seqBrowserMimeData = self.fmimeData()
  33. seqBrowserMimeData.setText(item.text(0))
  34. print item.text(0)
  35. # select the item we clicked
  36. self.setCurrentItem(item)
  37. if button == 1:
  38. print 'LEFT CLICK - DRAG'
  39. if button == 2:
  40. print 'RIGHT CLICK'
  41. else:
  42. print "select something you goober"
  43. pass
  44.  
  45. def dragEnterEvent(self, event):
  46. if event.mimeData().hasFormat('text/plain'):
  47. event.accept()
  48.  
  49. def dropEvent(self, event):
  50.  
  51. list = QtCore.QStringList()
  52. list = self.mimeTypes()
  53.  
  54. ##### THIS IS A COMPLETE HACK but for now 25 characters is what I need to strip off to make the string proper?
  55. ### its putting in a data structure array somehow still
  56.  
  57. text = event.mimeData().text()
  58. text = text[25:]
  59. #print "dropped"
  60. print (text)
  61. #print "here"
  62.  
  63.  
  64. class DragDrop(QtGui.QDialog):
  65. def __init__(self, parent=None):
  66. QtGui.QDialog.__init__(self, parent)
  67.  
  68. self.resize(280, 150)
  69. self.setWindowTitle('Simple Drag & Drop')
  70.  
  71. treeWidget = treeWidgetClass(self)
  72. treeWidget.setDragEnabled(True)
  73. treeWidget.setAcceptDrops(True)
  74. treeWidget.move(30, 65)
  75.  
  76. treeWidget2 = treeWidgetClass(self)
  77. treeWidget2.setDragEnabled(True)
  78. treeWidget2.setAcceptDrops(True)
  79. treeWidget2.move(300, 65)
  80.  
  81.  
  82. #button = Button("Button", self)
  83. #button.move(170, 65)
  84. item = QtGui.QTreeWidgetItem(treeWidget)
  85. item.setText(0,QtGui.QApplication.translate("", "jhgjhgljhgk hjgjhgjk jhgjhguyuy jhjhg jhgjhgjhg jhgjhgk ", None, QtGui.QApplication.UnicodeUTF8))
  86. item2 = QtGui.QTreeWidgetItem(treeWidget)
  87. item2.setText(0,QtGui.QApplication.translate("", "jhjhg jhgjhgjhg jhgjhgk ", None, QtGui.QApplication.UnicodeUTF8))
  88.  
  89.  
  90. screen = QtGui.QDesktopWidget().screenGeometry()
  91. size = self.geometry()
  92. self.move((screen.width()-size.width())/2,(screen.height()-size.height())/2)
  93.  
  94. app = QtGui.QApplication(sys.argv)
  95. icon = DragDrop()
  96. icon.show()
  97. app.exec_()
To copy to clipboard, switch view to plain text mode