In the application I'm writing using PyQt I want to do drag and drop functionality with dragging items from QListWidget to QLabel (setting text on QLabel basing on the text from item from QListWidget). In order to do that I made new class inheriting form QLabel to add dragEnterEvent and dropEvent. The code of my Label:
class Label(QLabel): def __init__(self, parent): super(Label, self).__init__(parent) self.setAcceptDrops(True) def dragEnterEvent(self, event): print('drag') print(event.mimeData().text()) if event.mimeData().hasText(): event.accept() else: event.ignore() def dropEvent(self, event): print('drop') self.setText(event.mimeData().text()) The problem is that when I drag item from QListWidget it has no text, so my code is not working. As I understand it's because when I'm dragging item from QListWidget I'm not dragging text but the whole widget (because, as I understand, the items in list are not strings but QListWidgetItem). According to different questions I've found here I suppose I should make a new class also for dragged item but at this point I don't know if I should do it for QListWidget or QListWidgetItem. Or maybe I should do this in completely different way?