[prev in list] [next in list] [prev in thread] [next in thread] 

List:       pykde
Subject:    [PyQt]  Drag and Drop of subclassed QListWidgetItem
From:       Massimiliano Costacurta <massi_srb () msn ! com>
Date:       2014-06-25 15:34:01
Message-ID: DUB111-W122314756EBAA766E1DE8AE9C190 () phx ! gbl
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]


Thank you for the replies Vincent. Did you also try to bring back the items from the \
bottom list to the top list? I tried both with python 2.7.3 and 3.3 and the behavior \
is the same (taht is crash). Thanks for your help!

> From: pyqt-request@riverbankcomputing.com
> Subject: PyQt Digest, Vol 119, Issue 25
> To: pyqt@riverbankcomputing.com
> Date: Tue, 24 Jun 2014 12:00:01 +0100
> 
> Send PyQt mailing list submissions to
> 	pyqt@riverbankcomputing.com
> 
> To subscribe or unsubscribe via the World Wide Web, visit
> 	http://www.riverbankcomputing.com/mailman/listinfo/pyqt
> or, via email, send a message with subject or body 'help' to
> 	pyqt-request@riverbankcomputing.com
> 
> You can reach the person managing the list at
> 	pyqt-owner@riverbankcomputing.com
> 
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of PyQt digest..."
> 
> 
> Today's Topics:
> 
> 1. Drag and Drop of subclassed QListWidgetItem (Massi)
> 2. Re: Drag and Drop of subclassed QListWidgetItem
> (Vincent Vande Vyvre)
> 3. Re: Drag and Drop of subclassed QListWidgetItem
> (Vincent Vande Vyvre)
> 
> 
> ----------------------------------------------------------------------
> 
> Message: 1
> Date: Tue, 24 Jun 2014 10:44:01 +0200
> From: "Massi" <massi_srb@msn.com>
> To: <pyqt@riverbankcomputing.com>
> Subject: [PyQt] Drag and Drop of subclassed QListWidgetItem
> Message-ID: <DUB111-DS30B502A7A96A835D1A32289C1E0@phx.gbl>
> Content-Type: text/plain; charset="iso-8859-1"
> 
> Hi everyone,
> 
> I'm encountering some poblems trying to implement drag and drop for a custom \
> QListWidgetItem. Here is some example code: 
> from PyQt4 import QtGui, QtCore
> import sys, os
> 
> class MyListWidgetItem(QtGui.QListWidgetItem):      
> def __init__(self, label, data, parent=None):
> super(QtGui.QListWidgetItem, self).__init__(label, parent=parent)
> self.data = data
> 
> def GetData(self):
> return self.data
> 
> class MyListWidget(QtGui.QListWidget):
> def __init__(self, type, parent=None):
> super(MyListWidget, self).__init__(parent)
> self.setDragDropMode(QtGui.QAbstractItemView.DragDrop)
> self.setSelectionMode(QtGui.QAbstractItemView.ExtendedSelection)
> self.setAcceptDrops(True)
> self.viewport().setAcceptDrops(True)
> self.setDropIndicatorShown(True)
> 
> def startDrag(self, supportedActions):
> drag = QtGui.QDrag(self)
> t = [i.GetData() for i in self.selectedItems()]
> mimeData = self.model().mimeData(self.selectedIndexes())
> mimeData.setText(str(t))
> drag.setMimeData(mimeData)
> if drag.start(QtCore.Qt.MoveAction) == QtCore.Qt.MoveAction:
> for item in self.selectedItems():
> self.takeItem(self.row(item))
> 
> def dragEnterEvent(self, event):
> if event.mimeData().hasUrls():
> event.ignore()
> else:
> event.accept()
> 
> def dragMoveEvent(self, event):
> if event.mimeData().hasUrls():
> event.ignore()
> else:
> event.accept()
> 
> def dropEvent(self, event):
> if event.mimeData().hasUrls():
> event.ignore()
> if isinstance(event.source(), MyListWidget):
> event.setDropAction(QtCore.Qt.MoveAction)
> super(MyListWidget, self).dropEvent(event)
> else:
> event.ignore()
> 
> def dropMimeData(self, index, mimedata, action):
> super(MyListWidget, self).dropMimeData(index, mimedata, action)
> return True
> 
> class Test(QtGui.QMainWindow):
> def __init__(self):
> super(QtGui.QMainWindow,self).__init__()
> myQWidget = QtGui.QWidget()
> myBoxLayout = QtGui.QVBoxLayout()
> myQWidget.setLayout(myBoxLayout)
> self.setCentralWidget(myQWidget)
> 
> self.listWidgetA = MyListWidget(self)
> self.listWidgetB = MyListWidget(self)
> 
> for i in range(5):
> listItemAInstance = MyListWidgetItem(str(i), i, parent=self.listWidgetA)
> 
> myBoxLayout.addWidget(self.listWidgetA)      
> myBoxLayout.addWidget(self.listWidgetB)   
> 
> if __name__ == '__main__':
> app = QtGui.QApplication(sys.argv)
> dialog_1 = Test()
> dialog_1.show()
> dialog_1.resize(480,320)
> sys.exit(app.exec_())
> 
> My custom class MyListWidgetItem has a 'data' field which in my real program holds \
> some information related to the item. If you run the code and try to drag and drop \
> items from the top list to the bottom one everything works, but if you then try to \
> bring them back to the top list you get this error: 
> Traceback (most recent call last):
> File "C:\Users\Massi\Desktop\t.py", line 23, in startDrag
> t = [i.GetData() for i in self.selectedItems()]
> AttributeError: 'QListWidgetItem' object has no attribute 'GetData'
> 
> It seems pretty clear that the default drag and drop behaviour ignores that the \
> list items have been subclassed, so I wonder which is the best to deal with this \
> situation. Any help is really appreciated. Thanks in advance!
> -------------- next part --------------
> An HTML attachment was scrubbed...
> URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20140624/8926cfb7/attachment-0001.html>
>  
> ------------------------------
> 
> Message: 2
> Date: Tue, 24 Jun 2014 12:24:43 +0200
> From: Vincent Vande Vyvre <vincent.vandevyvre@swing.be>
> To: pyqt@riverbankcomputing.com
> Subject: Re: [PyQt] Drag and Drop of subclassed QListWidgetItem
> Message-ID: <53A951EB.4070306@swing.be>
> Content-Type: text/plain; charset=UTF-8; format=flowed
> 
> Le 24/06/2014 10:44, Massi a écrit :
> > Hi everyone,
> > I'm encountering some poblems trying to implement drag and drop for a 
> > custom QListWidgetItem. Here is some example code:
> > from PyQt4 import QtGui, QtCore
> > import sys, os
> > class MyListWidgetItem(QtGui.QListWidgetItem):
> > def __init__(self, label, data, parent=None):
> > super(QtGui.QListWidgetItem, self).__init__(label, parent=parent)
> > self.data = data
> > def GetData(self):
> > return self.data
> > class MyListWidget(QtGui.QListWidget):
> > def __init__(self, type, parent=None):
> > super(MyListWidget, self).__init__(parent)
> > self.setDragDropMode(QtGui.QAbstractItemView.DragDrop)
> > self.setSelectionMode(QtGui.QAbstractItemView.ExtendedSelection)
> > self.setAcceptDrops(True)
> > self.viewport().setAcceptDrops(True)
> > self.setDropIndicatorShown(True)
> > def startDrag(self, supportedActions):
> > drag = QtGui.QDrag(self)
> > t = [i.GetData() for i in self.selectedItems()]
> > mimeData = self.model().mimeData(self.selectedIndexes())
> > mimeData.setText(str(t))
> > drag.setMimeData(mimeData)
> > if drag.start(QtCore.Qt.MoveAction) == QtCore.Qt.MoveAction:
> > for item in self.selectedItems():
> > self.takeItem(self.row(item))
> > def dragEnterEvent(self, event):
> > if event.mimeData().hasUrls():
> > event.ignore()
> > else:
> > event.accept()
> > def dragMoveEvent(self, event):
> > if event.mimeData().hasUrls():
> > event.ignore()
> > else:
> > event.accept()
> > def dropEvent(self, event):
> > if event.mimeData().hasUrls():
> > event.ignore()
> > if isinstance(event.source(), MyListWidget):
> > event.setDropAction(QtCore.Qt.MoveAction)
> > super(MyListWidget, self).dropEvent(event)
> > else:
> > event.ignore()
> > def dropMimeData(self, index, mimedata, action):
> > super(MyListWidget, self).dropMimeData(index, mimedata, action)
> > return True
> > class Test(QtGui.QMainWindow):
> > def __init__(self):
> > super(QtGui.QMainWindow,self).__init__()
> > myQWidget = QtGui.QWidget()
> > myBoxLayout = QtGui.QVBoxLayout()
> > myQWidget.setLayout(myBoxLayout)
> > self.setCentralWidget(myQWidget)
> > self.listWidgetA = MyListWidget(self)
> > self.listWidgetB = MyListWidget(self)
> > for i in range(5):
> > listItemAInstance = MyListWidgetItem(str(i), i, 
> > parent=self.listWidgetA)
> > myBoxLayout.addWidget(self.listWidgetA)
> > myBoxLayout.addWidget(self.listWidgetB)
> > if __name__ == '__main__':
> > app = QtGui.QApplication(sys.argv)
> > dialog_1 = Test()
> > dialog_1.show()
> > dialog_1.resize(480,320)
> > sys.exit(app.exec_())
> > My custom class MyListWidgetItem has a 'data' field which in my real 
> > program holds some information related to the item. If you run the 
> > code and try to drag and drop items from the top list to the bottom 
> > one everything works, but if you then try to bring them back to the 
> > top list you get this error:
> > Traceback (most recent call last):
> > File "C:\Users\Massi\Desktop\t.py", line 23, in startDrag
> > t = [i.GetData() for i in self.selectedItems()]
> > AttributeError: 'QListWidgetItem' object has no attribute 'GetData'
> > It seems pretty clear that the default drag and drop behaviour ignores 
> > that the list items have been subclassed, so I wonder which is the 
> > best to deal with this situation. Any help is really appreciated.
> > Thanks in advance!
> > 
> > 
> > _______________________________________________
> > PyQt mailing list    PyQt@riverbankcomputing.com
> > http://www.riverbankcomputing.com/mailman/listinfo/pyqt
> Works fine for me.
> 
> Platform Linux-3.2.0-48-generic-pae-i686-with-Ubuntu-12.04-precise
> Qt            4.8.1
> Python     2.7.3
> PyQt        4.9.1
> Sip            4.13.2
> 
> -- 
> Vincent V.V.
> Oqapy <https://launchpad.net/oqapy> . Qarte 
> <https://launchpad.net/qarte> . PaQager <https://launchpad.net/paqager>
> 
> 
> ------------------------------
> 
> Message: 3
> Date: Tue, 24 Jun 2014 12:34:01 +0200
> From: Vincent Vande Vyvre <vincent.vandevyvre@swing.be>
> To: pyqt@riverbankcomputing.com
> Subject: Re: [PyQt] Drag and Drop of subclassed QListWidgetItem
> Message-ID: <53A95419.4030603@swing.be>
> Content-Type: text/plain; charset=UTF-8; format=flowed
> 
> Le 24/06/2014 12:24, Vincent Vande Vyvre a écrit :
> > Le 24/06/2014 10:44, Massi a écrit :
> > > Hi everyone,
> > > I'm encountering some poblems trying to implement drag and drop for a 
> > > custom ...
> > Works fine for me.
> > 
> > Platform Linux-3.2.0-48-generic-pae-i686-with-Ubuntu-12.04-precise
> > Qt            4.8.1
> > Python     2.7.3
> > PyQt        4.9.1
> > Sip            4.13.2
> > 
> Works too with Python 3
> 
> Python        3.2.3
> Qt            4.8.1
> PyQt        4.10.2
> Sip            4.14.7
> 
> -- 
> Vincent V.V.
> Oqapy <https://launchpad.net/oqapy> . Qarte 
> <https://launchpad.net/qarte> . PaQager <https://launchpad.net/paqager>
> 
> 
> ------------------------------
> 
> Subject: Digest Footer
> 
> _______________________________________________
> PyQt mailing list
> PyQt@riverbankcomputing.com
> http://www.riverbankcomputing.com/mailman/listinfo/pyqt
> 
> ------------------------------
> 
> End of PyQt Digest, Vol 119, Issue 25
> *************************************
 		 	   		  


[Attachment #5 (text/html)]

<html>
<head>
<style><!--
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 12pt;
font-family:Calibri
}
--></style></head>
<body class='hmmessage'><div dir='ltr'>Thank you for the replies Vincent. Did you \
also try to bring back the items from the bottom list to the top list? I tried both \
with python 2.7.3 and 3.3 and the behavior is the same (taht is crash). Thanks for \
your help!<br><br><div>&gt; From: pyqt-request@riverbankcomputing.com<br>&gt; \
Subject: PyQt Digest, Vol 119, Issue 25<br>&gt; To: \
pyqt@riverbankcomputing.com<br>&gt; Date: Tue, 24 Jun 2014 12:00:01 +0100<br>&gt; \
<br>&gt; Send PyQt mailing list submissions to<br>&gt; \
pyqt@riverbankcomputing.com<br>&gt; <br>&gt; To subscribe or unsubscribe via the \
World Wide Web, visit<br>&gt; \
http://www.riverbankcomputing.com/mailman/listinfo/pyqt<br>&gt; or, via email, send a \
message with subject or body 'help' to<br>&gt; \
pyqt-request@riverbankcomputing.com<br>&gt; <br>&gt; You can reach the person \
managing the list at<br>&gt; 	pyqt-owner@riverbankcomputing.com<br>&gt; <br>&gt; When \
replying, please edit your Subject line so it is more specific<br>&gt; than "Re: \
Contents of PyQt digest..."<br>&gt; <br>&gt; <br>&gt; Today's Topics:<br>&gt; \
<br>&gt;    1. Drag and Drop of subclassed QListWidgetItem (Massi)<br>&gt;    2. Re: \
Drag and Drop of subclassed QListWidgetItem<br>&gt;       (Vincent Vande \
Vyvre)<br>&gt;    3. Re: Drag and Drop of subclassed QListWidgetItem<br>&gt;       \
(Vincent Vande Vyvre)<br>&gt; <br>&gt; <br>&gt; \
----------------------------------------------------------------------<br>&gt; \
<br>&gt; Message: 1<br>&gt; Date: Tue, 24 Jun 2014 10:44:01 +0200<br>&gt; From: \
"Massi" &lt;massi_srb@msn.com&gt;<br>&gt; To: \
&lt;pyqt@riverbankcomputing.com&gt;<br>&gt; Subject: [PyQt] Drag and Drop of \
subclassed QListWidgetItem<br>&gt; Message-ID: \
&lt;DUB111-DS30B502A7A96A835D1A32289C1E0@phx.gbl&gt;<br>&gt; Content-Type: \
text/plain; charset="iso-8859-1"<br>&gt; <br>&gt; Hi everyone,<br>&gt; <br>&gt; I'm \
encountering some poblems trying to implement drag and drop for a custom \
QListWidgetItem. Here is some example code:<br>&gt; <br>&gt; from PyQt4 import QtGui, \
QtCore<br>&gt; import sys, os<br>&gt; <br>&gt; class \
MyListWidgetItem(QtGui.QListWidgetItem):      <br>&gt;     def __init__(self, label, \
data, parent=None):<br>&gt;         super(QtGui.QListWidgetItem, \
self).__init__(label, parent=parent)<br>&gt;         self.data = data<br>&gt; \
<br>&gt;     def GetData(self):<br>&gt;         return self.data<br>&gt; <br>&gt; \
class MyListWidget(QtGui.QListWidget):<br>&gt;     def __init__(self, type, \
parent=None):<br>&gt;         super(MyListWidget, self).__init__(parent)<br>&gt;      \
self.setDragDropMode(QtGui.QAbstractItemView.DragDrop)<br>&gt;         \
self.setSelectionMode(QtGui.QAbstractItemView.ExtendedSelection)<br>&gt;         \
self.setAcceptDrops(True)<br>&gt;         \
self.viewport().setAcceptDrops(True)<br>&gt;         \
self.setDropIndicatorShown(True)<br>&gt; <br>&gt;     def startDrag(self, \
supportedActions):<br>&gt;         drag = QtGui.QDrag(self)<br>&gt;         t = \
[i.GetData() for i in self.selectedItems()]<br>&gt;         mimeData = \
self.model().mimeData(self.selectedIndexes())<br>&gt;         \
mimeData.setText(str(t))<br>&gt;         drag.setMimeData(mimeData)<br>&gt;         \
if drag.start(QtCore.Qt.MoveAction) == QtCore.Qt.MoveAction:<br>&gt;             for \
item in self.selectedItems():<br>&gt;                 \
self.takeItem(self.row(item))<br>&gt;                 <br>&gt;     def \
dragEnterEvent(self, event):<br>&gt;         if event.mimeData().hasUrls():<br>&gt;   \
event.ignore()<br>&gt;         else:<br>&gt;             event.accept()<br>&gt;       \
<br>&gt;     def dragMoveEvent(self, event):<br>&gt;         if \
event.mimeData().hasUrls():<br>&gt;             event.ignore()<br>&gt;         \
else:<br>&gt;             event.accept()<br>&gt;             <br>&gt;     def \
dropEvent(self, event):<br>&gt;         if event.mimeData().hasUrls():<br>&gt;        \
event.ignore()<br>&gt;         if isinstance(event.source(), MyListWidget):<br>&gt;   \
event.setDropAction(QtCore.Qt.MoveAction)<br>&gt;             super(MyListWidget, \
self).dropEvent(event)<br>&gt;         else:<br>&gt;             \
event.ignore()<br>&gt;             <br>&gt;     def dropMimeData(self, index, \
mimedata, action):<br>&gt;         super(MyListWidget, self).dropMimeData(index, \
mimedata, action)<br>&gt;         return True<br>&gt; <br>&gt; class \
Test(QtGui.QMainWindow):<br>&gt;     def __init__(self):<br>&gt;         \
super(QtGui.QMainWindow,self).__init__()<br>&gt;         myQWidget = \
QtGui.QWidget()<br>&gt;         myBoxLayout = QtGui.QVBoxLayout()<br>&gt;         \
myQWidget.setLayout(myBoxLayout)<br>&gt;         \
self.setCentralWidget(myQWidget)<br>&gt; <br>&gt;         self.listWidgetA = \
MyListWidget(self)<br>&gt;         self.listWidgetB = MyListWidget(self)<br>&gt; \
<br>&gt;         for i in range(5):<br>&gt;             listItemAInstance = \
MyListWidgetItem(str(i), i, parent=self.listWidgetA)<br>&gt; <br>&gt;         \
myBoxLayout.addWidget(self.listWidgetA)      <br>&gt;         \
myBoxLayout.addWidget(self.listWidgetB)   <br>&gt; <br>&gt; if __name__ == \
'__main__':<br>&gt;     app = QtGui.QApplication(sys.argv)<br>&gt;     dialog_1 = \
Test()<br>&gt;     dialog_1.show()<br>&gt;     dialog_1.resize(480,320)<br>&gt;     \
sys.exit(app.exec_())<br>&gt; <br>&gt; My custom class MyListWidgetItem has a 'data' \
field which in my real program holds some information related to the item. If you run \
the code and try to drag and drop items from the top list to the bottom one \
everything works, but if you then try to bring them back to the top list you get this \
error:<br>&gt; <br>&gt; Traceback (most recent call last):<br>&gt;   File \
"C:\Users\Massi\Desktop\t.py", line 23, in startDrag<br>&gt;     t = [i.GetData() for \
i in self.selectedItems()]<br>&gt; AttributeError: 'QListWidgetItem' object has no \
attribute 'GetData'<br>&gt; <br>&gt; It seems pretty clear that the default drag and \
drop behaviour ignores that the list items have been subclassed, so I wonder which is \
the best to deal with this situation. Any help is really appreciated.<br>&gt; Thanks \
in advance!<br>&gt; -------------- next part --------------<br>&gt; An HTML \
attachment was scrubbed...<br>&gt; URL: \
&lt;http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20140624/8926cfb7/attachment-0001.html&gt;<br>&gt; \
<br>&gt; ------------------------------<br>&gt; <br>&gt; Message: 2<br>&gt; Date: \
Tue, 24 Jun 2014 12:24:43 +0200<br>&gt; From: Vincent Vande Vyvre \
&lt;vincent.vandevyvre@swing.be&gt;<br>&gt; To: pyqt@riverbankcomputing.com<br>&gt; \
Subject: Re: [PyQt] Drag and Drop of subclassed QListWidgetItem<br>&gt; Message-ID: \
&lt;53A951EB.4070306@swing.be&gt;<br>&gt; Content-Type: text/plain; charset=UTF-8; \
format=flowed<br>&gt; <br>&gt; Le 24/06/2014 10:44, Massi a écrit :<br>&gt; &gt; Hi \
everyone,<br>&gt; &gt; I'm encountering some poblems trying to implement drag and \
drop for a <br>&gt; &gt; custom QListWidgetItem. Here is some example code:<br>&gt; \
&gt; from PyQt4 import QtGui, QtCore<br>&gt; &gt; import sys, os<br>&gt; &gt; class \
MyListWidgetItem(QtGui.QListWidgetItem):<br>&gt; &gt;     def __init__(self, label, \
data, parent=None):<br>&gt; &gt;         super(QtGui.QListWidgetItem, \
self).__init__(label, parent=parent)<br>&gt; &gt;         self.data = data<br>&gt; \
&gt;     def GetData(self):<br>&gt; &gt;         return self.data<br>&gt; &gt; class \
MyListWidget(QtGui.QListWidget):<br>&gt; &gt;     def __init__(self, type, \
parent=None):<br>&gt; &gt;         super(MyListWidget, self).__init__(parent)<br>&gt; \
&gt; self.setDragDropMode(QtGui.QAbstractItemView.DragDrop)<br>&gt; &gt; \
self.setSelectionMode(QtGui.QAbstractItemView.ExtendedSelection)<br>&gt; &gt;         \
self.setAcceptDrops(True)<br>&gt; &gt;         \
self.viewport().setAcceptDrops(True)<br>&gt; &gt;         \
self.setDropIndicatorShown(True)<br>&gt; &gt;     def startDrag(self, \
supportedActions):<br>&gt; &gt;         drag = QtGui.QDrag(self)<br>&gt; &gt;         \
t = [i.GetData() for i in self.selectedItems()]<br>&gt; &gt;         mimeData = \
self.model().mimeData(self.selectedIndexes())<br>&gt; &gt;         \
mimeData.setText(str(t))<br>&gt; &gt;         drag.setMimeData(mimeData)<br>&gt; &gt; \
if drag.start(QtCore.Qt.MoveAction) == QtCore.Qt.MoveAction:<br>&gt; &gt;             \
for item in self.selectedItems():<br>&gt; &gt;                 \
self.takeItem(self.row(item))<br>&gt; &gt;     def dragEnterEvent(self, \
event):<br>&gt; &gt;         if event.mimeData().hasUrls():<br>&gt; &gt;             \
event.ignore()<br>&gt; &gt;         else:<br>&gt; &gt;             \
event.accept()<br>&gt; &gt;     def dragMoveEvent(self, event):<br>&gt; &gt;         \
if event.mimeData().hasUrls():<br>&gt; &gt;             event.ignore()<br>&gt; &gt;   \
else:<br>&gt; &gt;             event.accept()<br>&gt; &gt;     def dropEvent(self, \
event):<br>&gt; &gt;         if event.mimeData().hasUrls():<br>&gt; &gt;             \
event.ignore()<br>&gt; &gt;         if isinstance(event.source(), \
MyListWidget):<br>&gt; &gt;             \
event.setDropAction(QtCore.Qt.MoveAction)<br>&gt; &gt;             \
super(MyListWidget, self).dropEvent(event)<br>&gt; &gt;         else:<br>&gt; &gt;    \
event.ignore()<br>&gt; &gt;     def dropMimeData(self, index, mimedata, \
action):<br>&gt; &gt;         super(MyListWidget, self).dropMimeData(index, mimedata, \
action)<br>&gt; &gt;         return True<br>&gt; &gt; class \
Test(QtGui.QMainWindow):<br>&gt; &gt;     def __init__(self):<br>&gt; &gt;         \
super(QtGui.QMainWindow,self).__init__()<br>&gt; &gt;         myQWidget = \
QtGui.QWidget()<br>&gt; &gt;         myBoxLayout = QtGui.QVBoxLayout()<br>&gt; &gt;   \
myQWidget.setLayout(myBoxLayout)<br>&gt; &gt;         \
self.setCentralWidget(myQWidget)<br>&gt; &gt;         self.listWidgetA = \
MyListWidget(self)<br>&gt; &gt;         self.listWidgetB = MyListWidget(self)<br>&gt; \
&gt;         for i in range(5):<br>&gt; &gt;             listItemAInstance = \
MyListWidgetItem(str(i), i, <br>&gt; &gt; parent=self.listWidgetA)<br>&gt; &gt;       \
myBoxLayout.addWidget(self.listWidgetA)<br>&gt; &gt;         \
myBoxLayout.addWidget(self.listWidgetB)<br>&gt; &gt; if __name__ == \
'__main__':<br>&gt; &gt;     app = QtGui.QApplication(sys.argv)<br>&gt; &gt;     \
dialog_1 = Test()<br>&gt; &gt;     dialog_1.show()<br>&gt; &gt;     \
dialog_1.resize(480,320)<br>&gt; &gt;     sys.exit(app.exec_())<br>&gt; &gt; My \
custom class MyListWidgetItem has a 'data' field which in my real <br>&gt; &gt; \
program holds some information related to the item. If you run the <br>&gt; &gt; code \
and try to drag and drop items from the top list to the bottom <br>&gt; &gt; one \
everything works, but if you then try to bring them back to the <br>&gt; &gt; top \
list you get this error:<br>&gt; &gt; Traceback (most recent call last):<br>&gt; &gt; \
File "C:\Users\Massi\Desktop\t.py", line 23, in startDrag<br>&gt; &gt;     t = \
[i.GetData() for i in self.selectedItems()]<br>&gt; &gt; AttributeError: \
'QListWidgetItem' object has no attribute 'GetData'<br>&gt; &gt; It seems pretty \
clear that the default drag and drop behaviour ignores <br>&gt; &gt; that the list \
items have been subclassed, so I wonder which is the <br>&gt; &gt; best to deal with \
this situation. Any help is really appreciated.<br>&gt; &gt; Thanks in \
advance!<br>&gt; &gt;<br>&gt; &gt;<br>&gt; &gt; \
_______________________________________________<br>&gt; &gt; PyQt mailing list    \
PyQt@riverbankcomputing.com<br>&gt; &gt; \
http://www.riverbankcomputing.com/mailman/listinfo/pyqt<br>&gt; Works fine for \
me.<br>&gt; <br>&gt; Platform \
Linux-3.2.0-48-generic-pae-i686-with-Ubuntu-12.04-precise<br>&gt; Qt            \
4.8.1<br>&gt; Python     2.7.3<br>&gt; PyQt        4.9.1<br>&gt; Sip            \
4.13.2<br>&gt; <br>&gt; -- <br>&gt; Vincent V.V.<br>&gt; Oqapy \
&lt;https://launchpad.net/oqapy&gt; . Qarte <br>&gt; \
&lt;https://launchpad.net/qarte&gt; . PaQager \
&lt;https://launchpad.net/paqager&gt;<br>&gt; <br>&gt; <br>&gt; \
------------------------------<br>&gt; <br>&gt; Message: 3<br>&gt; Date: Tue, 24 Jun \
2014 12:34:01 +0200<br>&gt; From: Vincent Vande Vyvre \
&lt;vincent.vandevyvre@swing.be&gt;<br>&gt; To: pyqt@riverbankcomputing.com<br>&gt; \
Subject: Re: [PyQt] Drag and Drop of subclassed QListWidgetItem<br>&gt; Message-ID: \
&lt;53A95419.4030603@swing.be&gt;<br>&gt; Content-Type: text/plain; charset=UTF-8; \
format=flowed<br>&gt; <br>&gt; Le 24/06/2014 12:24, Vincent Vande Vyvre a écrit \
:<br>&gt; &gt; Le 24/06/2014 10:44, Massi a écrit :<br>&gt; &gt;&gt; Hi \
everyone,<br>&gt; &gt;&gt; I'm encountering some poblems trying to implement drag and \
drop for a <br>&gt; &gt;&gt; custom ...<br>&gt; &gt; Works fine for me.<br>&gt; \
&gt;<br>&gt; &gt; Platform \
Linux-3.2.0-48-generic-pae-i686-with-Ubuntu-12.04-precise<br>&gt; &gt; Qt            \
4.8.1<br>&gt; &gt; Python     2.7.3<br>&gt; &gt; PyQt        4.9.1<br>&gt; &gt; Sip   \
4.13.2<br>&gt; &gt;<br>&gt; Works too with Python 3<br>&gt; <br>&gt; Python        \
3.2.3<br>&gt; Qt            4.8.1<br>&gt; PyQt        4.10.2<br>&gt; Sip            \
4.14.7<br>&gt; <br>&gt; -- <br>&gt; Vincent V.V.<br>&gt; Oqapy \
&lt;https://launchpad.net/oqapy&gt; . Qarte <br>&gt; \
&lt;https://launchpad.net/qarte&gt; . PaQager \
&lt;https://launchpad.net/paqager&gt;<br>&gt; <br>&gt; <br>&gt; \
------------------------------<br>&gt; <br>&gt; Subject: Digest Footer<br>&gt; \
<br>&gt; _______________________________________________<br>&gt; PyQt mailing \
list<br>&gt; PyQt@riverbankcomputing.com<br>&gt; \
http://www.riverbankcomputing.com/mailman/listinfo/pyqt<br>&gt; <br>&gt; \
------------------------------<br>&gt; <br>&gt; End of PyQt Digest, Vol 119, Issue \
25<br>&gt; *************************************<br></div> 		 	   		  </div></body> \
</html>


[Attachment #6 (text/plain)]

_______________________________________________
PyQt mailing list    PyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic