[PyQt] 'mouseMoveEvent' for a 'QListWidget' subclass stops drag-and-drop

Phil Thompson phil at riverbankcomputing.com
Tue Nov 22 11:31:39 GMT 2011


On Tue, 22 Nov 2011 11:12:21 +0000, "Timothy W. Grove" <tim_grove at sil.org>
wrote:
> Why would reimplementing a 'mouseMoveEvent' for a 'QListWidget' subclass

> stop drag-and-drop?
> 
> The class below just holds a list of icons. Without the mouseMoveEvent 
> method I can drag the icons around; with it I can't. Under wxPython I 
> would have added 'event.skip()' at the end of my event handling method 
> and expected the method to pass on the event when it finished. Is there 
> something similar under PyQt4?
> 
> class ItemList(QListWidget):
>      def __init__(self, parent=None):
>          super(ItemList, self).__init__(parent)
>          self.setViewMode(QListView.IconMode)
>          self.setResizeMode(QListView.Adjust)
>          self.setMouseTracking(True)
>          self.current_item = None
>          self.setDragEnabled(True)
>          self.setAcceptDrops(True)
> 
>      def mouseMoveEvent(self, event):
>          item = self.itemAt(event.pos())
>          if item != self.current_item:
>              self.emit(SIGNAL("item_found"), item)
>              self.current_item = item

Call the super-class method at the end of your reimplementation.

Phil


More information about the PyQt mailing list