Im trying to implement drag and drop to a table widget and getting an error Trying to construct an instance of an invalid type, type id: 793994105
. There's multiple lines of this but with different ids. How can i get this working without errors so that I can see the print statement when I drag and drop a file eg pdf?
from PyQt5 import QtCore, QtWidgets
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(353, 320)
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.tableWidget = QtWidgets.QTableWidget(self.centralwidget)
self.tableWidget.setGeometry(QtCore.QRect(48, 50, 256, 192))
self.tableWidget.setAcceptDrops(True)
self.tableWidget.setDragDropMode(QtWidgets.QAbstractItemView.DragDrop)
self.tableWidget.setDefaultDropAction(QtCore.Qt.CopyAction)
self.tableWidget.setColumnCount(2)
self.tableWidget.setObjectName("tableWidget")
self.tableWidget.setRowCount(0)
types = ['text/uri-list']
types.extend(self.tableWidget.mimeTypes())
self.tableWidget.mimeTypes = lambda: types
MainWindow.setCentralWidget(self.centralwidget)
self.tableWidget.viewport().installEventFilter(self.tableWidget)
def eventFilter(self, source, event):
if (event.type() == QtCore.QEvent.Drop and
event.mimeData().hasUrls()):
print('Dropped')
return True
return super().eventFilter(source, event)
if __name__ == '__main__':
import sys
app = QtWidgets.QApplication(sys.argv)
Window = QtWidgets.QMainWindow()
ui = Ui_MainWindow()
ui.setupUi(Window)
Window.show()
sys.exit(app.exec_())
I already tried implementing these drag and drop events with no luck too:
def dragEnterEvent(self, event):
print('dragged')
def dropEvent(self, event):
print('dropped')
Full error is:
Trying to construct an instance of an invalid type, type id: 793994105
Trying to construct an instance of an invalid type, type id: 793011571
Trying to construct an instance of an invalid type, type id: 53299009
Trying to construct an instance of an invalid type, type id: 339825483
Trying to construct an instance of an invalid type, type id: 846557999
Trying to construct an instance of an invalid type, type id: 594112103
Trying to construct an instance of an invalid type, type id: 694380910
Trying to construct an instance of an invalid type, type id: 863265134
Trying to construct an instance of an invalid type, type id: 842025326
Trying to construct an instance of an invalid type, type id: 858735433
Trying to construct an instance of an invalid type, type id: 891630128
Trying to construct an instance of an invalid type, type id: 624046145
Trying to construct an instance of an invalid type, type id: 610667786