Drag from a QListWidget causing crash
-
wrote on 14 Jan 2020, 16:36 last edited by Niagarer
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! -
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 ?
-
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 ?
wrote on 14 Jan 2020, 19:55 last edited by Niagarer@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
-
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.
-
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.
-
Thanks !
2/6