Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Drag from a QListWidget causing crash



  • Hi!
    This is surely something trivial, but I just don't get it. Unfortunately, the QtForPython documentation does not really address this (yet).
    I am trying to implement the simplest possible drag and drop system between a QListWidget and a QGraphicsView. Basically, this should just send a string to the QGraphicsView.
    You can just copy the code.

    import sys
    from PySide2.QtWidgets import QApplication, QMainWindow, QWidget, QVBoxLayout, QListWidget, QListWidgetItem, QAbstractItemView
    from PySide2.QtCore import QMimeData, QByteArray
    
    class ClassesListWidget(QListWidget):
        def __init__(self):
            super(ClassesListWidget, self).__init__()
    
            self.addItem(QListWidgetItem('first'))
            self.addItem(QListWidgetItem('second'))
    
            self.setSelectionMode(QAbstractItemView.SingleSelection)
            self.setDragEnabled(True)
            self.viewport().setAcceptDrops(True)
            self.setDropIndicatorShown(True)
    
    
        def mimeTypes(self):
            return ['text/plain']
    
        def mimeData(self, items):
            mime_data = QMimeData()
            data = QByteArray(bytes('testdata', 'utf-8'))
            mime_data.setData('text/plain', data)
            return mime_data
    
    
    class MainWindow(QMainWindow):
        def __init__(self):
            super(MainWindow, self).__init__()
            self.setCentralWidget(ClassesListWidget())
    
    
    if __name__ == '__main__':
        app = QApplication(sys.argv)
    
        mw = MainWindow()
        mw.show()
    
        sys.exit(app.exec_())
    

    it works without the mimeData method (but of course, I want to transfer a specific string, not the item itself). With the method, the application just crashes when I try to drag an item without any further useful error message
    Do you know whats wrong with the code above?
    Thanks!


  • Lifetime Qt Champion

    Hi,

    Would you mind sharing the rest of the script so that people can try reproducing your issue ?

    By the way, are you using PySide2 or PyQt5 ? Which version ? On what OS ?



  • @SGaist
    Yeah, it's actually just that, I don't drag any items outside, the dragging itself is the problem (so the environment shouldn't matter I guess).
    I just updated the question with a small working code producing the same result.

    Sorry, forgot to point out, I am using PySide2-5.14.0 on Win10


  • Lifetime Qt Champion

    Well, there's nothing fundamentally wrong that I can see with what you wrote so I think you may have found a bug in PySide2. It also crashes on macOS.

    Please check the bug report system to see if there's already something there. If not, please open a new report providing the code you posted here.



  • @SGaist Oh, really! Ok...
    Bugreport


  • Lifetime Qt Champion

    Thanks !


Log in to reply