[PyQt] Dropping on ListView
Toralf Wittner
wittner at fossilverlag.de
Wed Aug 29 09:40:48 EDT 2001
Hello world,
consider the following code fragment that is supposed to print the
pointer to the QListViewItem a text is dropped on. Unfortunatly it
doesn't work. I used the function 'QListViewItem* itemAt(const QPoint &
screenPos)' that should return the QListViewItem, but it just doesn't do it.
Maybe someone is able to tell me what's wrong here and how I could master
this problem. Thanks for any comments!
Yours sincerely,
Toralf.
------------------------------------------------------------------------------
#!/usr/bin/env python
from sys import argv
from qt import *
class DropDemo(QWidget):
def __init__(self,parent=None,name=None):
QWidget.__init__(self,parent,name)
self.setAcceptDrops(1)
self.l = QListView(self)
self.l.setGeometry(10,10,100,60)
self.l.addColumn("Column 1")
self.l.insertItem(QListViewItem(self.l, "Hello"))
def dragEnterEvent(self, event):
event.accept(QTextDrag.canDecode(event))
def dropEvent(self, event):
text = QString()
item = self.l.itemAt(event.pos())
if QTextDrag.decode(event, text):
print item
if __name__ == '__main__':
a = QApplication(argv)
w = DropDemo()
w.setCaption("Drag and Drop Test")
w.resize(120,80)
a.setMainWidget(w)
w.show()
a.exec_loop()
More information about the Python-list
mailing list