Discussion:
[Interest] QListView with delegate: support drag outside of QApplication
Frank Rueter | OHUfx
2018-07-30 03:24:03 UTC
Permalink
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>
Frank Rueter | OHUfx
2018-07-31 09:13:04 UTC
Permalink
Anybody?
Been trying to play with the view's dragMoveEvent to take over the
default drag event's mime data and create a custom QDrag instance with
it, but that crashes. I also tried just adding test to the event's mime
data, but that  has no effect.
Maybe I do need to just re-implement the drag from scratch?

It feels like there should be a more elegant solution, right?!

Cheers,
frank
Post by Frank Rueter | OHUfx
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>
_______________________________________________
Interest mailing list
http://lists.qt-project.org/mailman/listinfo/interest
Frank Rueter | OHUfx
2018-08-05 02:33:22 UTC
Permalink
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_() |
Post by Frank Rueter | OHUfx
Anybody?
Been trying to play with the view's dragMoveEvent to take over the
default drag event's mime data and create a custom QDrag instance with
it, but that crashes. I also tried just adding test to the event's
mime data, but that  has no effect.
Maybe I do need to just re-implement the drag from scratch?
It feels like there should be a more elegant solution, right?!
Cheers,
frank
Post by Frank Rueter | OHUfx
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>
_______________________________________________
Interest mailing list
http://lists.qt-project.org/mailman/listinfo/interest
_______________________________________________
Interest mailing list
http://lists.qt-project.org/mailman/listinfo/interest
​

Loading...