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

Timothy W. Grove tim_grove at sil.org
Tue Nov 22 11:12:21 GMT 2011


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

Best regards,
Tim Grove


More information about the PyQt mailing list