[PySide] QListView with delegate: support drag outside of QApplication
Frank Rueter | OHUfx
frank at ohufx.com
Sun Aug 5 04:33:54 CEST 2018
For posterity, this is the solution:
|import sys from PySide import QtGui, QtCore class
MyModel(QtGui.QStandardItemModel): def __init__(self, w, parent=None):
super(MyModel, self).__init__(parent) def mimeData(self, indexes):
mimeData = super(MyModel, self).mimeData(indexes)
mimeData.setText('test') return mimeData class MyList(QtGui.QListView):
def __init__(self, parent=None): super(MyList, self).__init__(parent)
self.setDragEnabled(True) self.setAcceptDrops(True) if __name__ ==
'__main__': app = QtGui.QApplication(sys.argv) list1 = MyList() list2 =
MyList() model1 = MyModel(list1) model2 = MyModel(list1)
model2.setItemPrototype(QtGui.QStandardItem()) foods = [ 'Cookie dough',
'Hummus', 'Spaghetti', 'Dal makhani', 'Chocolate whipped cream' ] for
food in foods: item = QtGui.QStandardItem(food) model1.appendRow(item)
list1.setModel(model1) list2.setModel(model2) w = QtGui.QSplitter()
w.addWidget(list1) w.addWidget(list2) w.show() w.raise_() app.exec_() |
On 29/07/18 8:25 PM, Frank Rueter | OHUfx wrote:
> Hi all,
>
> I have an app that uses two QListViews with delegates.
> The user can drag ad drop items from one view into the other to create
> something like a shopping list.
> So far so good.
> Now I need to enable the user to also drag an item out of the
> application entirely.
> Is it possible to access the drag event data that the list view
> produces by default, so I don’t have to re-invent the wheel for the
> already functioning internal drag&drop?
>
> Here is a simplified example that just needs support for dragging an
> item outside of the QApplication.
>
> Any tips would be much appreciated.
>
> Cheers,
> frank
>
> |import sys from PySide import QtGui, QtCore app =
> QtGui.QApplication(sys.argv) class MyList(QtGui.QListView): def
> __init__(self, parent=None): super(MyList, self).__init__(parent)
> self.setDragEnabled(True) self.setAcceptDrops(True) list1 = MyList()
> list2 = MyList() model1 = QtGui.QStandardItemModel(list1) model2 =
> QtGui.QStandardItemModel(list1)
> model2.setItemPrototype(QtGui.QStandardItem()) foods = [ 'Cookie
> dough', 'Hummus', 'Spaghetti', 'Dal makhani', 'Chocolate whipped
> cream' ] for food in foods: item = QtGui.QStandardItem(food)
> model1.appendRow(item) list1.setModel(model1) list2.setModel(model2) w
> = QtGui.QSplitter() w.addWidget(list1) w.addWidget(list2) w.show()
> w.raise_() app.exec_() |
>
> --
>
> ohufxLogo 50x50 <http://www.ohufx.com>
> *vfx compositing <http://ohufx.com/compositing.html> | *workflow
> customisation and consulting <http://ohufx.com/customising.html>* *
> *<http://ohufx.com/compositing.html>*
> <http://www.nukepedia.com/nubridge>
>
>
> Your gateway to over 1,000 free tools... right inside of Nuke
> <http://www.nukepedia.com/nubridge>
>
>
>
> _______________________________________________
> PySide mailing list
> PySide at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/pyside
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/pyside/attachments/20180805/6a0c58a7/attachment.html>
More information about the PySide
mailing list