Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from PySide import QtCore, QtGui
- class MyItem(QtGui.QStandardItem):
- '''This is the item I'd like to drop into the view'''
- def __init__(self, parent=None):
- super(MyItem, self).__init__(parent)
- class ReceivingView(QtGui.QListView):
- '''Custom view to show the problem - i.e. the dropEvent produces a QStandardItem rather than MyItem'''
- def __init__(self, parent=None):
- super(ReceivingView, self).__init__(parent)
- def dropEvent(self, event):
- # let the default behaviour do it's thing:
- super(ReceivingView, self).dropEvent(event)
- # now show received item is QStandardItem, not the sent custom item
- item = self.model().item(self.model().rowCount() - 1)
- print item
- if __name__ == "__main__":
- import sys
- app = QtGui.QApplication(sys.argv)
- mw = QtGui.QMainWindow()
- w = QtGui.QSplitter()
- mw.setCentralWidget(w)
- # models
- model1 = QtGui.QStandardItemModel()
- model2 = QtGui.QStandardItemModel()
- for i in xrange(20):
- #item = QtGui.QStandardItem()
- item = MyItem()
- item.setData(str(i), QtCore.Qt.DisplayRole)
- model1.appendRow(item)
- # views
- view1 = QtGui.QListView()
- view2 = ReceivingView()
- for v in (view1, view2):
- v.setViewMode(QtGui.QListView.IconMode)
- view1.setModel(model1)
- view2.setModel(model2)
- w.addWidget(view1)
- w.addWidget(view2)
- mw.show()
- mw.raise_()
- sys.exit(app.exec_())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement